def test_add_square():
    """
    Проверка работы метода сложения площадей
    """
    circle1 = Circle('name1', 2)
    circle2 = Circle('name2', 3)
    assert round(circle1.add_square(circle2), 2) == 40.84
Esempio n. 2
0
    def test_diffrent_color_place(self):
        c = Circle.parse({
            'x': 1,
            'y': 2,
            'radius': 3,
            'color': '#0000ff'
        }, {}, Color("#123456"))
        self.assertEqual(c.color, Color("#0000ff"))

        c = Circle.parse({
            'x': 1,
            'y': 2,
            'radius': 3,
            'color': 'aaa'
        }, {'aaa': "#ff0000"}, Color("#123456"))
        self.assertEqual(c.color, Color("#ff0000"))
Esempio n. 3
0
 def handle_mouse_button_up(self, coord):
     """
     Recupere la coordonee d'un point sur le cercle quand l'utilisateur arrete de cliquer
     """
     if self.center is not None:
         coord = list(coord)
         to_draw = Circle(self.center, coord,
                          self.whiteboard.get_config(["active_color"]),
                          self.whiteboard.get_config(["toolbar_y"]))
         now = datetime.now()
         timestamp = datetime.timestamp(now)
         self.whiteboard.draw(to_draw, timestamp)
         self.center = None
Esempio n. 4
0
def load_figures(json_figures):
    figs = []
    for fig in json_figures:
        t = fig['type']
        if t == "point":
            figs.append(Point(int(fig['x']), int(fig['y'])))
        elif t == "polygon":
            figs.append(Polygon(fig['points']))
        elif t == "rectangle":
            figs.append(
                Rectangle(int(fig['x']), int(fig['y']), int(fig['width']),
                          int(fig['height'])))
        elif t == "square":
            figs.append(Square(int(fig['x']), int(fig['y']), int(fig['size'])))
        elif t == "circle":
            figs.append(
                Circle(int(fig['x']), int(fig['y']), int(fig['radius'])))
        if "color" in fig:
            figs[-1].color = fig['color']
    return figs
def test_angles():
    """
    Проверка на корректность количества углов
    """
    circle = Circle('name', 1)
    assert circle.angles == 0
Esempio n. 6
0
 def test_parse(self):
     c = Circle.parse({'x': 1, 'y': 2, 'radius': 3}, {}, Color("#123456"))
     self.assertEqual(c.x, 1)
     self.assertEqual(c.y, 2)
     self.assertEqual(c.radius, 3)
     self.assertEqual(c.color, Color("#123456"))
Esempio n. 7
0
from figures import Rectangle, Square, Circle

if __name__ == '__main__':
    print(Rectangle(10, 5, 'Blue'))
    print(Square(7, 'Green'))
    print(Circle(3, 'Yellow'))
Esempio n. 8
0
from figures import Rectangle, Square, Circle

#прямоугольники
rect1 = Rectangle(2, 3)
rect2 = Rectangle(3, 4)

#штаны спанчбоба
square1 = Square(5)
square2 = Square(6)

#окружности
circle1 = Circle(6)
circle2 = Circle(7)

figures = [rect1, square1, circle1, rect2, circle2, square2]

for figure in figures:
    if isinstance(figure, Rectangle):
        print(f"Figure Rectangle with area {figure.get_area()}")
    elif isinstance(figure, Square):
        print(f"Figure Square with area {figure.get_area()}")
    elif isinstance(figure, Circle):
        print(f"Figure Circle with area {figure.get_area()}")
    else:
        print("Error in head)")
Esempio n. 9
0
def test_circle_area():
    """Тест вычисления площади окружности"""
    circle = Circle(radius=10)
    assert int(circle.find_area()) == approx(314, abs=2e-1)
Esempio n. 10
0
from figures import Rectangle, Square, Circle

#прямоугольники
rect1 = Rectangle(2, 3, 4, 5)
rect2 = Rectangle(3, 4, 5, 6)

#штаны спанчбоба
square1 = Square(1, 2, 5)
square2 = Square(3, 4, 6)

#окружности
circle1 = Circle(10, 11, 6)
circle2 = Circle(12, 13, 7)

figures_ = [rect1, square1, circle1, rect2, circle2, square2]

for figure in figures_:
    if isinstance(figure, Rectangle):
        #print(f"Figure Rectangle with area {figure.get_area()} & coordinates {figure.get_coordinates()}")
        print(figure.get_string())
    elif isinstance(figure, Square):
        #print(f"Figure Rectangle with area {figure.get_area()} & coordinates {figure.get_coordinates()}")
        print(figure.get_string())
    elif isinstance(figure, Circle):
        #print(f"Figure Rectangle with area {figure.get_area()} & coordinates {figure.get_coordinates()}")
        print(figure.get_string())
    else:
        print("Error in head)")
def test_perimeter():
    """
    Проверка на корректность вычисления длины окружности
    """
    circle = Circle('name', 3)
    assert round(circle.perimeter, 2) == 18.85
Esempio n. 12
0
    def test_errors(self):
        with self.assertRaises(ValueError):
            Circle.parse({'xq': 1, 'y': 2, 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'y': 2, 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'yq': 2, 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': 2, 'radiusqq': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': 2}, {}, Color("#123456"))
        with self.assertRaises(ValueError):
            Circle.parse({'x': 1, 'y': 2, 'radius': 3}, {}, Color("#123456"))

        with self.assertRaises(TypeError):
            Circle.parse({'x': (), 'y': 2, 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': [], 'radius': 3}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': 2, 'radius': {}}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': 2, 'radius': {}}, {}, Color("#123456"))
            Circle.parse({'x': 1, 'y': 2, 'radius': 3}, {}, Color("#1"))
def test_area():
    """
    Проверка на корректность вычисления площади
    """
    circle = Circle('name', 2)
    assert round(circle.area, 2) == 12.57
Esempio n. 14
0
from figures import Rectangle, Square, Circle

rect_1 = Rectangle(3, 4)
rect_2 = Rectangle(12, 5)

print(rect_1.get_area())
print(rect_2.get_area())

square_1 = Square(5)
square_2 = Square(10)

print(square_1.get_area_square(), square_2.get_area_square())

circ_1 = Circle(5)
circ_2 = Circle(7)

print(circ_1.get_area_circle(), circ_2.get_area_circle())

figures = [rect_1, rect_2, square_1, square_2, circ_1, circ_2]

for figure in figures:
    if isinstance(figure, Square):
        print(figure.get_area_square())
    elif isinstance(figure, Circle):
        print(figure.get_area_circle())
    else:
        print(figure.get_area())
Esempio n. 15
0
def test_create_circle():
    """Тест создания окружности"""
    circle = Circle(radius=10)
    assert circle.name == 'Circle'
Esempio n. 16
0
def test_add_areas_error():
    """Тест вызова исключения с невалидными параметрами"""
    var = 10
    circle = Circle(radius=10)
    with pytest.raises(AttributeError):
        circle.add_area(var)
Esempio n. 17
0
def test_add_areas():
    """Тест вычисления суммы площадей двух фигур"""
    circle = Circle(radius=10)
    triangle = Triangle(a=5, b=6)
    assert circle.add_area(triangle) == approx(329, abs=2e-1)
Esempio n. 18
0
from figures import Rectangle, Square, Circle

rect_1 = Rectangle(15, 12)
rect_2 = Rectangle(17, 5)
print(rect_1.get_area(), rect_2.get_area())

square_1 = Square(5)
square_2 = Square(11)
print(square_1.get_area(), square_2.get_area())

circle_1 = Circle(15)
circle_2 = Circle(9)
print(circle_1.get_area(), circle_2.get_area())

figures = [rect_1, rect_2, square_1, square_2, circle_1, circle_2]
for figure in figures:
    print(figure.get_area())
def test_name(name):
    """
    Проверка на корректность заданного имени
    """
    circle = Circle(name, 1)
    assert circle.name == name
Esempio n. 20
0
from figures import Circle

a = Circle(2)
b = Circle(3)
for square in a, b:
    print(f'square = {square.get_area_circle()}')
Esempio n. 21
0
from figures import Rectangle, Square, Circle

rect_1 = Rectangle(3, 4)
rect_2 = Rectangle(12, 5)

print(f"Площадь 1го прямоугольника: {rect_1.getArea()}")
print(f"Площадь 2го прямоугольника: {rect_2.getArea()}")

square_1 = Square(5)
square_2 = Square(10)

print(f"\nПлощадь 1го квадрата: {square_1.getSquareArea()}")
print(f"Площадь 2го квадрата: {square_2.getSquareArea()}")

circle_1 = Circle(3)
circle_2 = Circle(4)

print(f"\nПлощадь 1го круга: {circle_1.getArea()}")
print(f"Площадь 2го круга: {circle_2.getArea()}")

my_figures = [rect_1, rect_2, square_1, square_2, circle_1, circle_2]

print("\nПлощади всех имеющихся фигур:")

for elem in my_figures:
    if isinstance(elem, Square):
        print(elem.getSquareArea())
    else:
        print(elem.getArea())
Esempio n. 22
0
from figures import Rectangle, Square, Circle

rect_1 = Rectangle(3, 4)
rect_2 = Rectangle(12, 5)
#вывод площади наших двух прямоугольников
print(rect_1.get_area_rectangle())
print(rect_2.get_area_rectangle())
print("\n")

square_1 = Square(10)
square_2 = Square(6)

print(square_1.get_area_square(), square_2.get_area_square())
print("\n")

circ_1 = Circle(25)
circ_2 = Circle(11)

print(circ_1.get_area_circle(), circ_2.get_area_circle())
print("\n")

figures = [rect_1, rect_2, square_1, square_2, circ_1, circ_2]

for figure in figures:
    if isinstance(figure, Square):
        print("Square: " + str(figure.get_area_square()))
    elif isinstance(figure, Rectangle):
        print("Rectangle: " + str(figure.get_area_rectangle()))
    elif isinstance(figure, Circle):
        print("Circle: " + str(figure.get_area_circle()))
Esempio n. 23
0
def test_circle_perimeter():
    """Тест вычисления периметра окружности"""
    circle = Circle(radius=10)
    assert int(circle.find_perimeter()) == approx(62, abs=2e-1)