Project poligonal calculator

Hi,
my code not pass the test for two errors but I don’t know what is the problem.

FAIL: test_rectangle_string (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-polygon-area-calculator/test_module.py”, line 39, in test_rectangle_string
self.assertEqual(
AssertionError: ‘Rectangle(width=6, height=3)’ != ‘Rectangle(width=3, height=6)’

  • Rectangle(width=6, height=3)
    ? ^ ^
  • Rectangle(width=3, height=6)
    ? ^ ^
    : Expected string representation of rectangle to be “Rectangle(width=3, height=6)”

======================================================================
FAIL: test_set_attributes (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-polygon-area-calculator/test_module.py”, line 97, in test_set_attributes
self.assertEqual(
AssertionError: ‘Square(side=2)’ != ‘Square(side=4)’

  • Square(side=2)
    ? ^
  • Square(side=4)
    ? ^
    : Expected string representation of square after setting width to be “Square(side=4)”

Ran 15 tests in 0.002s

FAILED (failures=2)

my code:
def str(self):
return f"Rectangle(width={self.lunghezza}, height={self.altezza})"

def str(self):
return f"Square(side={self.lato})"

Expected string representation of rectangle to be “Rectangle(width=3, height=6)”

Width and height looks like they could be reversed here. The test expects Rectangle(width=3, height=6) but you return
Rectangle(width=6, height=3)

1 Like

ok it is working but I receive a one error:

AIL: test_set_attributes (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-polygon-area-calculator/test_module.py”, line 84, in test_set_attributes
self.assertEqual(
AssertionError: ‘Rectangle(width=8, height=7)’ != ‘Rectangle(width=7, height=8)’

  • Rectangle(width=8, height=7)
    ? ^ ^
  • Rectangle(width=7, height=8)
    ? ^ ^
    : Expected string representation of rectangle after setting new values to be “Rectangle(width=7, height=8)”

Ran 15 tests in 0.009s

FAILED (failures=1)

where is the problem now?

Can you understand what the error is saying?

AssertionError: ‘Rectangle(width=8, height=7)’ != ‘Rectangle(width=7, height=8)’

It’s the same error as before

Can you link to your code? I’ll take a look

1 Like

Yes boilerplate-polygon-area-calculator - Replit

Ok, I’ve taken a look at your code and I see the problem. Again, in the error message it looks like your height and width are reversed.

This is from the problem description:

When a Rectangle object is created, it should be initialized with width and height attributes.

Look at your Class __init__

Look at how a rectangle is created:

shape_calculator.Rectangle(3, 6)

Now look at these lines from your code carefully:

  def set_height(self,altezza2):
    self.altezza=altezza2
    
  def __str__(self):
    return f"Rectangle(width={self.altezza}, height={self.lunghezza})"

See the problem?

1 Like

Yes i understand e solve it but i receive a one error on f string of square. The error is “Square(side=2)”!=“Square(side=4)”. I don’t understand it and thank you very much.

The test is setting the width on a square: set_width(4)

What happens if you create a square and use the set_width(4) function? (not set_side())

Additionally, the set_width and set_height methods on the Square class should set both the width and height.

Ok it work . Thanks you!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.