That was a big detail I missed, thank you! After fixing the setters, now the only step that doesn’t check out is 16. Here’s the change I made to my code:
I’ve run the test code dhess posted before with a set_side() line in between to see the changes, like so:
sq = Square(9)
print(sq.get_area()) # 81
sq.set_side(4)
print(sq.get_diagonal()) # 5.656854249492381
sq.set_side(2) # added test line
print(sq.get_diagonal()) # 2.8284271247461903
print(sq)
print(sq.get_picture())
And it returns the correct result of the diagonal of the new square, with a side length of 2. As for the string representation, the get_picture() call returns:
**
**
But I’ve noticed that with the new test lines, the console returns different results for the get_amount_inside(sq) at the end, now returning 32, when the previous returned result was 8.
Edit: now I get it, after adding the test just like the message above, the set_height(6) doesn’t update the square’s side length because the string representation checks only for the square’s width, not height. Changing it to return f"Square(side={self.side})" throws an AttributeError, however.
Edit 2: I solved it in the end by changing the set_width() and set_height() to make sure they check the class name and update width and height correctly.
In the future, try to focus on exactly what is mentioned in the test:
16. An instance of the Square class should have a different string representation after setting new values by using .set_width() or set_height().
So you should be testing .set_width() and set_height() to see if they work.
“String representation” refers to the output of the __str__(self): method, not get_picture, although both should change in any case. The language there is a bit confusing " get_picture: Returns a string that represents the shape"
See user story 3 as well:
If an instance of a Rectangle is represented as a string, it should look like: Rectangle(width=5, height=10).