Hi, all. I’m stuck on Task 14 of this exercise. I can’t rationalize why I keep failing this test. nor do I understand why the expected dimensions are (90, 75) when the window is position within the parameters of the screen size. Below is what the test is actually asking for.
const programWindow = new ProgramWindow();
const newPosition = new Position(710, 525);
programWindow.move(newPosition);
const newSize = new Size(1000, 1000);
programWindow.resize(newSize);
expect(programWindow.size.width).toBe(90);
expect(programWindow.size.height).toBe(75);
Below is my code with the program window class. I’m just not understanding why it needs to be resized when it’s within the screen width and height. I keep failing against the resize respects limits due to position and screen size. I truly don’t know what I’m missing here.
export class ProgramWindow {
constructor(screenSize, size, position){
this.screenSize = new Size(800, 600);
this.size = new Size();
this.position = new Position();
}
resize(size){
if (size.width < 1 || size.height < 1){
this.size.width = 1;
this.size.height = 1;
} else {
this.size.width = size.width;
this.size.height = size.height;
}
}
move(position){
let maxX = this.screenSize.width - this.size.width;
let maxY = this.screenSize.height - this.size.height;
if (position.x < 0 || position.y < 0){
this.position.x = 0;
this.position.y = 0;
} else if(position.x > this.screenSize.width || position.y > this.screenSize.height){
this.position.x = maxX;
this.position.y = maxY;
} else {
this.position.x = position.x;
this.position.y = position.y;
}
}
}