def test_add_square(): name_1 = 'MyTest1' a1 = 4 name_2 = 'MyTest2' a2 = 7 area_1 = a1**2 area_2 = a2**2 s1 = Square(name_1, a1) s2 = Square(name_2, a2) assert isclose(s1.add_area(s2), area_1 + area_2)
def __init__(self, side_length): self._figures_list = [Triangle(side_length), Square(side_length)] self._sum_areas = 0
from figure import Rectangle, Square rectangle = Rectangle(3, 5) print(rectangle) print(rectangle.circuit()) square = Square(2, 4) print(square.a) print(square.b) print(square) print(square.area())
signal = False clickedPiece = 0 figureboard = [[22, 23, 24, 26, 25, 24, 23, 22], [21, 21, 21, 21, 21, 21, 21, 21], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [11, 11, 11, 11, 11, 11, 11, 11], [12, 13, 14, 16, 15, 14, 13, 12]] for h in range(CHESSBOARD_TILES): currColor = None if (BOARD_NUMS[h] == 1): currColor = WHITE_COLOR else: currColor = BLACK_COLOR chessboard.add(Square((64 * x, 64 * y), currColor, (64, 64))) if h % 8 == 7: x += 1 y = 0 else: y += 1 for x, row in enumerate(FIGURE_NUMS, start=0): for y, figType in enumerate(row, start=0): if (figType != 0): figures.add(Figure((64 * y, 64 * x), figType)) # x coordinates increase from left to right, y coordinates increase from top to bottom naHod = True
def test_square_init(): name = 'MyTest' a = 5 s = Square(name, a) assert s.name == name assert s.a == a
def test_add_square_negative(): name_1 = 'MyTest1' a = 2.4 s = Square(name_1, a) with pytest.raises(TypeError): s.add_area(123)
def test_square_perimeter(): name = 'MyTest' a = 5 s = Square(name, a) p = a * 4 assert isclose(p, s.perimeter)
def test_square_area(): name = 'MyTest' a = 5 s = Square(name, a) area = a**2 assert isclose(area, s.area)