Task 5 Windowing-System Exercise

Hi Everyone,

I’m having some trouble with task 5 in the Windowing-System Exercise. I have a solution I believe works however when I run the test, I’m failing against the move respects limits due to screen and window size check.

Checking the task descript gives the following example:

if the window's size is at x= 250,y= 100 and a move to x= 600,y= 200 is requested, then the window would be moved to x= 550,y= 200 as the screen is not large enough in thex direction to fully accommodate the request.

How is the example coming to the conclusion that the new position of X and Y should be (550,200) when the Screen size is (250,100)? Should the new position not be (250,100) since that’s the window size?

// The setup
const programWindow = new ProgramWindow();
const newSize = new Size(100, 100);
programWindow.resize(newSize);
const newPosition = new Position(750, 650);
programWindow.move(newPosition);

// The tests
expect(programWindow.position.x).toBe(700);
expect(programWindow.position.y).toBe(500);

Whilst the ProgramWindow size is changed to 100x100, the screen size remains 800x600

If you were to move that screen to 750, 650, you would have 50 pixels of the window width (750 (left most pixel) + 100 (window width) = 850 (right most pixel) - 800 (screen width) = 50) outside of the screen. So it would bump it left to 700, making it fit perfectly flush with the right side of the screen.

Same goes for the height.

It took me some time to wrap my head around what you were describing but I understand now and was able pass that check. Thanks!

1 Like