Windowing System Help

I apologize ahead of time. I couldn’t figure out how to upload my testing screenshots. I’ve tried testing this code numerous times to no avail. I’ve even tried looking at solutions that have passed and can’t seem to get it to work. Can someone kindly take a look and see if you can pinpoint what’s happening?

ProgramWindow.php

<?php

class ProgramWindow
{
    public $x;
    public $y;
    public $width;
    public $height;

    function __construct()
    {
        $this->x = 0;
        $this->y = 0;
        $this->width = 800;
        $this->height = 600;
    }
    
    function resize(Size $size) {
        $this->width = $size->width;
        $this->height = $size->height;
    }
    
    function move(Position $position) {
        $this->x = $position->x;
        $this->y = $position->y;
    }
}

Size.php

<?php

class Size
{
    public $height;
    public $width;
    
    function __construct($newHeight, $newWidth) {
        $this->height = $newHeight;
        $this->width = $newWidth;
    }
}

Position.php

<?php

class Position 
{
    public $x;
    public $y;
    
    function __construct($newX, $newY) 
    {
        $this->x = $newX;
        $this->y = $newY;
    }
}

Are you getting an error message? If so, what is it saying?

The issue lies within the Position class.

Test 8

ProgramWindowTest::testPositionHasConstructorSettingInitialValues
Failed asserting that 70 matches expected 30.

ProgramWindowTest.php:108

Test 9

ProgramWindowTest::testProgramWindowMove
Failed asserting that 235 matches expected 40.

ProgramWindowTest.php:121

Thank you for using codeblocks and not uploading images which encode text.

1 Like

Focusing on a test at a time, I’d suggest reviewing the Task 4 instructions for how you should set up the constructor.

Got it! Ended up swapping placement of the arguments within the Position constructor, ($y, $x), and it passed. Any idea why that would matter??

No problem! Makes things a lot more readable.

1 Like

Without seeing both versions of the code, it’s hard to know what you’re talking about. But swapping the arguments is the difference between Position(5, 500) having a height (or y-position) of 5 vs 500. Those are very different values.