hello everyone, I am currently completing the polygon calculator and have encountered a couple of errors that i cannot seem to wrap my head around. On pycharm the code work and does what it is supposed to but on replit the test fail. Which have lead me to think that my mistake lies in the formatting and “general setup” of the code as opposed to it not being able to perform the the task described by the challenge.
Here is my code and below are the 6 tests that is are not passing. I checked the test modules and tried to find the source of my errors but failed. So I am sure that i must be missing something…
Some errors I just straight up not understand, like the first one for example: why does the test_rectangle_picture claim that I return “none” my methods all have a “return” and the code on pycharm works nicely? And what is wrong with the string representation of the shapes?
Thank you all for your help, I am sure that it must be some silly error, but these errors are even more frustrating when you know you are almost finished with a project with the exception of a few quick to fix bugs!
# This entrypoint file to be used in development. Start by reading README.md
import shape_calculator
from unittest import main
class Rectangle:
@classmethod
def from_str(cls, str_height, str_width):
height = int(str_height.lstrip("height ="))
width = int(str_width.lstrip("width ="))
cls(width, height)
return cls(width, height)
def __init__(self, width, height):
self.width = width
self.height = height
def set_width(self, width):
self.width = width
def set_height(self, height):
self.height = height
def get_area(self):
area = self.width * (self.height)
return area
def get_perimeter(self):
perimeter = 2 * (self.width + self.height)
return perimeter
def get_diagonal(self):
diagonal = ((self.width) ** 2 + (self.height) ** 2) ** 0.5
return diagonal
def get_picture(self):
if isinstance(self.width,str) == True or isinstance(self.height, str) == True:
return"Rectangle(width={}, height={})".format(self.width, self.height)
elif self.width > 50 or self.height > 50:
return "Too big for picture."
else:
for i in range(int(self.height)):
x = (self.width) * ("*")
y = print(x)
return y
def get_amount_inside(self, shape_2):
self.shape2 = shape_2
x = self.get_area() // shape_2.get_area()
if x > 0:
return x
else:
return 0
class Square(Rectangle):
@classmethod
def from_str(cls, str_side):
side = int(str_side.lstrip("side ="))
cls(side, side)
return cls(side, side)
def __init__(self, side):
super().__init__(side, side)
def set_side(self, side):
self.side = side
def get_picture(self):
if isinstance(self.side,str) == True :
return"Square(side={})".format(self.side)
elif self.side > 50:
return "Too big for picture."
else:
for i in range(int(self.side)):
x = (self.side) * ("*")
y = print(x)
return y
#code already included in the challenge:
main(module='test_module', exit=False)
rect = shape_calculator.Rectangle(5, 10)
print(rect.get_area())
rect.set_width(3)
print(rect.get_perimeter())
print(rect)
sq = shape_calculator.Square(9)
print(sq.get_area())
sq.set_side(4)
print(sq.get_diagonal())
print(sq)
# Run unit tests automatically
main(module='test_module', exit=False)
Here are my the tests I am failing
python main.py
........*******
FFF.F*****
F.
======================================================================
FAIL: test_rectangle_picture (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 80, in test_rectangle_picture
self.assertEqual(actual, expected, 'Expected rectangle picture to be different.')
AssertionError: None != '*******\n*******\n*******\n' : Expected rectangle picture to be different.
======================================================================
FAIL: test_rectangle_string (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 28, in test_rectangle_string
self.assertEqual(actual, expected, 'Expected string representation of rectangle to be "Rectangle(width=3, height=6)"')
AssertionError: '<shape_calculator.Rectangle object at 0x7f7136baeb80>' != 'Rectangle(width=3, height=6)'
- <shape_calculator.Rectangle object at 0x7f7136baeb80>
+ Rectangle(width=3, height=6)
: Expected string representation of rectangle to be "Rectangle(width=3, height=6)"
======================================================================
FAIL: test_set_atributes (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 66, in test_set_atributes
self.assertEqual(actual, expected, 'Expected string representation of rectangle after setting new values to be "Rectangle(width=7, height=8)"')
AssertionError: '<shape_calculator.Rectangle object at 0x7f7136bae9a0>' != 'Rectangle(width=7, height=8)'
- <shape_calculator.Rectangle object at 0x7f7136bae9a0>
+ Rectangle(width=7, height=8)
: Expected string representation of rectangle after setting new values to be "Rectangle(width=7, height=8)"
======================================================================
FAIL: test_square_string (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 33, in test_square_string
self.assertEqual(actual, expected, 'Expected string representation of square to be "Square(side=5)"')
AssertionError: '<shape_calculator.Square object at 0x7f7136baea90>' != 'Square(side=5)'
- <shape_calculator.Square object at 0x7f7136baea90>
+ Square(side=5)
: Expected string representation of square to be "Square(side=5)"
======================================================================
FAIL: test_squaree_picture (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 86, in test_squaree_picture
self.assertEqual(actual, expected, 'Expected square picture to be different.')
AssertionError: None != '**\n**\n' : Expected square picture to be different.
----------------------------------------------------------------------
Ran 15 tests in 0.002s
FAILED (failures=5)
50
26
<shape_calculator.Rectangle object at 0x7f7137f4c130>
81
12.727922061357855
<shape_calculator.Square object at 0x7f7136baeac0>
........*******
FFF.F*****
F.
======================================================================
FAIL: test_rectangle_picture (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 80, in test_rectangle_picture
self.assertEqual(actual, expected, 'Expected rectangle picture to be different.')
AssertionError: None != '*******\n*******\n*******\n' : Expected rectangle picture to be different.
======================================================================
FAIL: test_rectangle_string (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 28, in test_rectangle_string
self.assertEqual(actual, expected, 'Expected string representation of rectangle to be "Rectangle(width=3, height=6)"')
AssertionError: '<shape_calculator.Rectangle object at 0x7f7136304850>' != 'Rectangle(width=3, height=6)'
- <shape_calculator.Rectangle object at 0x7f7136304850>
+ Rectangle(width=3, height=6)
: Expected string representation of rectangle to be "Rectangle(width=3, height=6)"
======================================================================
FAIL: test_set_atributes (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 66, in test_set_atributes
self.assertEqual(actual, expected, 'Expected string representation of rectangle after setting new values to be "Rectangle(width=7, height=8)"')
AssertionError: '<shape_calculator.Rectangle object at 0x7f7136304be0>' != 'Rectangle(width=7, height=8)'
- <shape_calculator.Rectangle object at 0x7f7136304be0>
+ Rectangle(width=7, height=8)
: Expected string representation of rectangle after setting new values to be "Rectangle(width=7, height=8)"
======================================================================
FAIL: test_square_string (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 33, in test_square_string
self.assertEqual(actual, expected, 'Expected string representation of square to be "Square(side=5)"')
AssertionError: '<shape_calculator.Square object at 0x7f7136304c10>' != 'Square(side=5)'
- <shape_calculator.Square object at 0x7f7136304c10>
+ Square(side=5)
: Expected string representation of square to be "Square(side=5)"
======================================================================
FAIL: test_squaree_picture (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator-5/test_module.py", line 86, in test_squaree_picture
self.assertEqual(actual, expected, 'Expected square picture to be different.')
AssertionError: None != '**\n**\n' : Expected square picture to be different.
----------------------------------------------------------------------
Ran 15 tests in 0.002s
FAILED (failures=5)
^C