def test_figures_types(self) -> None: """Test the figure arch_enemy functionality""" s1: figures.Square = figures.Square(10) s2: figures.Square = figures.Square(5) c1: figures.Circle = figures.Circle(10) c2: figures.Circle = figures.Circle(5) self.assertFalse(figures.Figure.are_archenemy(s1, c1)) self.assertFalse(figures.Figure.are_archenemy(c2, s2)) self.assertTrue(figures.Figure.are_archenemy(c1, c2)) self.assertTrue(figures.Figure.are_archenemy(s1, s2))
def SquareTest(): square = figures.Square(5) assert square.area() == 25 square.doubleSize() assert square.sidelen == 10 assert square.area() == 100 del square with pytest.raises(Exception): square = figures.Circle("test") square.area()
def load_figures(figures_table, content, palette): for figure in content: if figure["type"] == "point": figures_table.append(figures.Point(figure, palette)) elif figure["type"] == "square": figures_table.append(figures.Square(figure, palette)) elif figure["type"] == "rectangle": figures_table.append(figures.Rectangle(figure, palette)) elif figure["type"] == "circle": figures_table.append(figures.Circle(figure, palette)) elif figure["type"] == "polygon": figures_table.append(figures.Polygon(figure, palette)) else: print("Unknown type of figure")
def test_figures_areas(self) -> None: """Test the figure area functionality""" s: figures.Square = figures.Square(10) c: figures.Circle = figures.Circle(10) self.assertAlmostEqual(s.area() + c.area(), figures.Figure.areas([s, c]))
def test_square(self) -> None: """Init a square and test its functionality""" s: figures.Square = figures.Square(5) self.assertEqual(s.width, 5) self.assertEqual(s.width, s.height) self.assertIs(s.area(), 25)
def setUp(self): self.square = figures.Square(4)
#!/usr/bin/python # -*- coding: utf-8 -*- """Работа с классоми геометрических фигур в рамках задания 1.9.1 """ import figures myfigures = [figures.Rectangle(5, 10), figures.Square(15), figures.Circle(8)] for figure in myfigures: print(figure.get_area())
# Instantiating drawing logic # Draw(CANVAS, color, brushWidth, x1, y1, x2, y2) line = figures.Line() # Draw(CANVAS, color, brushWidth, x1, y1, x2, y2, x3, y3) triangle = figures.Triangle() # Draw(CANVAS, color, brushWidth, cx, cy, length) equilateralTriangle = figures.EquilateralTriangle() # Draw(CANVAS, color, brushWidth, cx, cy, width, height) rectangle = figures.Rectangle() # Draw(CANVAS, color, brushWidth, cx, cy, length) square = figures.Square() # Draw(CANVAS, color, brushWidth, cx, cy, verticalRadius, horizontalRadius) ellipse = figures.Ellipse() # Draw(CANVAS, color, brushWidth, cx, cy, radius) circle = figures.Circle() # Interpreter's additional functions def ChangeCanvasColor(newColor): global canvasColor global canvas canvasColor = newColor canvas["background"] = canvasColor
def test_negative_side(self): with pytest.raises(Exception) as excinfo: a = figures.Square(-1) assert str(excinfo.value) == "Side can not be less than zero"
[(4, 50.26548245743669, 25.132741228718345, True, ""), (0, 0, 0, False, "радиус должен быть целым положительным числом > 0")]) def test_create_circle(r, area, perimeter, exp_success, exp_error): circle = None try: circle = f.Circle(r) except Exception as e: error = str(e) if exp_success: assert circle is not None assert circle.r == r assert circle.area == area assert circle.perimeter == perimeter else: assert error == exp_error @pytest.mark.parametrize( 'other_figure, exp_result', [(f.Circle(2), 25.132741228718345), (f.Square(4), 28.566370614359172), (None, "Метод принимает только объекты класса Figure")]) def test_add_square(other_figure, exp_result): circle = f.Circle(2) try: result = circle.add_square(other_figure) except Exception as e: result = str(e) assert result == exp_result
def test_side_is_float(self): a = figures.Square(2.5) assert a.get_area() == 2.5 ** 2 assert a.get_perimeter() == 10
def test_side_equal_0(self): a = figures.Square(0) assert a.get_area() == 0 assert a.get_perimeter() == 0
def test_side_equal_2(self): a = figures.Square(2) assert a.get_area() == 4 assert a.get_perimeter() == 8
def test_side_equal_1(self): a = figures.Square(1) assert a.get_area() == 1 assert a.get_perimeter() == 4
def test_init_without_parameters(self): a = figures.Square() assert a.get_area() == 1 assert a.get_perimeter() == 4