Hey guys, i here is my code. But i always get some errors. please take a look at the code. Thanks
class Rectangle:
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.heigt = height
def get_area(self):
area = self.width * self.height
return area
def get_perimeter(self):
perimeter = 2 * self.width + 2 * self.height
return perimeter
def get_diagonal(self):
diagonal = (self.width ** 2 + self.height ** 2) ** 0.5
return diagonal
def get_picture(self):
if self.width <= 50 and self.height <= 50:
picture = ("*" * self.width + "\n") * self.height
return picture
else:
return "Too big for picture."
def get_amount_inside(self, shape):
fitInWidth = int(self.width / shape.width)
fitInHeight = int(self.height / shape.height)
if fitInHeight != 0 and fitInWidth != 0:
return max(fitInHeight, fitInWidth)
else:
return 0
def __str__(self):
return "Rectangle(width=" + str(self.width) + ", height=" + str(self.height) + ")"
class Square(Rectangle):
def __init__(self, length):
self.length = length
self.width = self.length
self.height = self.length
def set_side(self, length):
self.length = length
self.width = length
self.height = length
def set_width(self, width):
self.set_side(width)
def set_height(self, height):
self.set_side(height)
def __str__(self):
return "Square(side=" + str(self.length) + ")"
50
26
Rectangle(width=3, height=10)
81
5.656854249492381
Square(side=4)
....F...F.F....
======================================================================
FAIL: test_get_amount_inside (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator/test_module.py", line 100, in test_get_amount_inside
self.assertEqual(actual, expected, 'Expected `get_amount_inside` to return 6.')
AssertionError: 3 != 6 : Expected `get_amount_inside` to return 6.
======================================================================
FAIL: test_rectangle_picture (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator/test_module.py", line 80, in test_rectangle_picture
self.assertEqual(actual, expected, 'Expected rectangle picture to be different.')
AssertionError: '*******\n*******\n*******\n*******\n*******\n*******\n' != '*******\n*******\n*******\n'
*******
*******
*******
- *******
- *******
- *******
: Expected rectangle picture to be different.
======================================================================
FAIL: test_set_atributes (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-polygon-area-calculator/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: 'Rectangle(width=7, height=6)' != 'Rectangle(width=7, height=8)'
- Rectangle(width=7, height=6)
? ^
+ 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.003s
FAILED (failures=3)