def test_add_square():
    """
    Проверка работы метода сложения площадей
    """
    rectangle1 = Rectangle('name1', 1, 1, 3, 2)
    rectangle2 = Rectangle('name2', 1, 1, 2, 2)
    assert rectangle1.add_square(rectangle2) == 3
Exemplo n.º 2
0
def test_create_rectangle_with_valid_values(a, b):
    """Тест создания четырехугольника"""
    if a > b:
        rectangle = Rectangle(a, b)
        assert rectangle.name == 'Rectangle'
    elif a < b:
        rectangle = Rectangle(a, b)
        assert rectangle.name == 'Rectangle'
    elif a == b:
        pytest.raises(ValueError)
Exemplo n.º 3
0
 def draw_figure(x, y, game_field):
     i = int(y / 30)
     j = int(x / 30)
     Rectangle.draw_rectangle_yellow(x, y)
     Rectangle.draw_rectangle_yellow(x + 30, y)
     Rectangle.draw_rectangle_yellow(x, y - 30)
     Rectangle.draw_rectangle_yellow(x + 30, y - 30)
     game_field[i][j] = 3
     game_field[i][j + 1] = 3
     game_field[i - 1][j] = 3
     game_field[i - 1][j + 1] = 3
Exemplo n.º 4
0
    def test_diffrent_color_place(self):
        p = Rectangle.parse(
            {
                'x': 1,
                'y': 2,
                'height': 2,
                'width': 3,
                'color': "(0, 255, 0)"
            }, {}, Color("#123456"))
        self.assertEqual(p.color, Color("#00ff00"))

        p = Rectangle.parse(
            {
                'x': 1,
                'y': 2,
                'height': 2,
                'width': 3,
                'color': "cos"
            }, {"cos": "#00ff00"}, Color("#123456"))
        self.assertEqual(p.color, Color("#00ff00"))
Exemplo n.º 5
0
 def test_parse(self):
     p = Rectangle.parse({
         'x': 1,
         'y': 2,
         'height': 2,
         'width': 3
     }, {}, Color("#123456"))
     self.assertEqual(p.x, 1)
     self.assertEqual(p.y, 2)
     self.assertEqual(p.height, 2)
     self.assertEqual(p.width, 3)
     self.assertEqual(p.color, Color("#123456"))
Exemplo n.º 6
0
 def handle_mouse_button_up(self, coord):
     """
     Recupere la deuxieme coordonee d'un coin du rectangle a tracer quand l'utilisateur arrete de cliquer
     """
     if self.c1 is not None:
         coord = list(coord)
         # on ne veut pas depasser sur la toolbar
         coord[1] = max(self.whiteboard.get_config(["toolbar_y"]), coord[1])
         to_draw = Rectangle(self.c1, coord,
                             self.whiteboard.get_config(["active_color"]))
         now = datetime.now()
         timestamp = datetime.timestamp(now)
         self.whiteboard.draw(to_draw, timestamp)
         self.c1 = None
Exemplo n.º 7
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():
    """
    Проверка на корректность количества углов
    """
    rectangle = Rectangle('name', 1, 1, 1, 2)
    assert rectangle.angles == 4
def test_perimeter():
    """
    Проверка на корректность вычисления периметра
    """
    rectangle = Rectangle('name', 1, 1, 4, 2)
    assert rectangle.perimeter == 8
def test_area():
    """
    Проверка на корректность вычисления площади
    """
    rectangle = Rectangle('name', 1, 1, 2, 4)
    assert rectangle.area == 3
Exemplo n.º 11
0
 def draw_if_next(x, y):
     Rectangle.draw_rectangle_green(x, y)
     Rectangle.draw_rectangle_green(x + 30, y)
     Rectangle.draw_rectangle_green(x + 30, y - 30)
     Rectangle.draw_rectangle_green(x + 60, y - 30)
Exemplo n.º 12
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())
Exemplo n.º 13
0
                painter.setBrush(QBrush(Qt.blue))

                points = []
                for point in figure:
                    points.append(QPoint(point['x'], point['y']))
                painter.drawPolygon(points)
                continue


if __name__ == '__main__':
    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = './platforms'
    app = QApplication(sys.argv)
    figure_widget = FigureWidget()

    # Создайте список фигур
    rect_1 = Rectangle(20, 30, 400, 200)
    rect_2 = Rectangle(100, 300, 300, 50)
    ell = Ellipse(200, 400, 150, 100)
    zamk = CloseFigure({
        'x': 200,
        'y': 500
    }, {
        'x': 300,
        'y': 600
    }, {
        'x': 250,
        'y': 650
    }, {
        'x': 100,
        'y': 700
    }, {
Exemplo n.º 14
0
 def draw_figure(x, y, game_field, position):
     i = int(y / 30)
     j = int(x / 30)
     if position == 1:
         Rectangle.draw_rectangle_purple(x, y)
         Rectangle.draw_rectangle_purple(x + 30, y)
         Rectangle.draw_rectangle_purple(x + 60, y)
         Rectangle.draw_rectangle_purple(x + 30, y - 30)
         game_field[i][j] = 4
         game_field[i][j + 1] = 4
         game_field[i][j + 2] = 4
         game_field[i - 1][j + 1] = 4
     elif position == 2:
         Rectangle.draw_rectangle_purple(x, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y)
         Rectangle.draw_rectangle_purple(x + 30, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y - 60)
         game_field[i - 1][j] = 4
         game_field[i][j + 1] = 4
         game_field[i - 1][j + 1] = 4
         game_field[i - 2][j + 1] = 4
     elif position == 3:
         Rectangle.draw_rectangle_purple(x, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y)
         Rectangle.draw_rectangle_purple(x + 60, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y - 30)
         game_field[i - 1][j] = 4
         game_field[i][j + 1] = 4
         game_field[i - 1][j + 2] = 4
         game_field[i - 1][j + 1] = 4
     elif position == 4:
         Rectangle.draw_rectangle_purple(x + 60, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y)
         Rectangle.draw_rectangle_purple(x + 30, y - 30)
         Rectangle.draw_rectangle_purple(x + 30, y - 60)
         game_field[i - 1][j + 2] = 4
         game_field[i][j + 1] = 4
         game_field[i - 1][j + 1] = 4
         game_field[i - 2][j + 1] = 4
Exemplo n.º 15
0
Arquivo: app.py Projeto: kveron/tetris
line_full = 0
score = 0
figures = []
for j in range(10000):
    figures.append(random.randint(1, 7))
figure = figures[0]
next_figure = figures[-1]
figure_checked = [0, 0, 0, 0]
timing = time.time()
view_score = score_text.render(score.__str__(), 1, WHITE)
pygame.draw.rect(background, (0, 0, 0), (400, 100, 100, 100))
background.blit(view_score, (450, 100))
for i in range(0, 570, 30):
    for j in range(0, 360, 30):
        if i == 0 or i == 540 or j == 0 or j == 330:
            Rectangle.draw_rectangle_gray(j + 15, i + 15)
            game_field[int(i / 30)][int(j / 30)] = 1

x = START_X
y = START_Y

while True:
    clock.tick(FPS)
    if TIMER == 0 and (int(time.time() - timing)) % 20 == 0:
        if SPEED <= 3:
            SPEED = 3
        SPEED -= 1
    for i in range(30, 540, 30):
        for j in range(30, 320, 30):
            if game_field[int(i / 30)][int(j / 30)] == 0:
                Rectangle.draw_rectangle_background(j, i)
Exemplo n.º 16
0
def test_add_areas_error():
    """Тест вызова исключения с невалидными параметрами"""
    var = 10
    rectangle = Rectangle(a=10, b=5)
    with pytest.raises(AttributeError):
        rectangle.add_area(var)
Exemplo n.º 17
0
def test_add_areas():
    """Тест вычисления суммы площадей двух фигур"""
    rectangle = Rectangle(a=10, b=5)
    assert rectangle.add_area(rectangle) == 100
Exemplo n.º 18
0
def test_rectangle_area():
    """Тест вычисления площади четырехугольника"""
    rectangle = Rectangle(a=10, b=5)
    assert rectangle.find_area() == 50
Exemplo n.º 19
0
def test_rectangle_perimeter():
    """Тест вычисления периметра четырехугольника"""
    rectangle = Rectangle(a=10, b=5)
    assert rectangle.find_perimeter() == 30
Exemplo n.º 20
0
 def draw_if_next(x, y):
     Rectangle.draw_rectangle_orange(x, y)
     Rectangle.draw_rectangle_orange(x + 30, y)
     Rectangle.draw_rectangle_orange(x + 60, y - 30)
     Rectangle.draw_rectangle_orange(x + 60, y)
def test_name(name):
    """
    Проверка на корректность заданного имени
    """
    rectangle = Rectangle(name, 1, 1, 3, 3)
    assert rectangle.name == name
Exemplo n.º 22
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)")
Exemplo n.º 23
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)")
Exemplo n.º 24
0
from figures import Rectangle, Square, Circle

if __name__ == '__main__':
    print(Rectangle(10, 5, 'Blue'))
    print(Square(7, 'Green'))
    print(Circle(3, 'Yellow'))
Exemplo n.º 25
0
 def draw_if_next(x, y):
     Rectangle.draw_rectangle_purple(x, y)
     Rectangle.draw_rectangle_purple(x + 30, y)
     Rectangle.draw_rectangle_purple(x + 60, y)
     Rectangle.draw_rectangle_purple(x + 30, y - 30)
Exemplo n.º 26
0
    def test_errors(self):
        with self.assertRaises(ValueError):
            Rectangle.parse({
                'y': 2,
                'height': 2,
                'width': 3
            }, {}, Color("#123456"))
            Rectangle.parse({
                'x': 1,
                'height': 2,
                'width': 3
            }, {}, Color("#123456"))
            Rectangle.parse({'x': 1, 'y': 2, 'width': 3}, {}, Color("#123456"))
            Rectangle.parse({
                'x': 1,
                'y': 2,
                'height': 2
            }, {}, Color("#123456"))
            Rectangle.parse({'x': 1, 'y': 2, 'height': 2, 'width': 3}, {}, 1)

        with self.assertRaises(TypeError):
            Rectangle.parse({
                'x': {},
                'y': 2,
                'height': 2,
                'width': 3
            }, {}, Color("#123456"))
            Rectangle.parse(
                {
                    'x': 1,
                    'y': (),
                    'height': 1,
                    'width': 3,
                    'color': "(0, 255, 0)"
                }, {}, Color("#123456"))
            Rectangle.parse(
                {
                    'x': 1,
                    'y': 2,
                    'height': [],
                    'width': 3,
                    'color': "(0, 255, 0)"
                }, {}, Color("#123456"))
            Rectangle.parse(
                {
                    'x': 1,
                    'y': 2,
                    'height': 2,
                    'width': "",
                    'color': "(0, 255, 0)"
                }, {}, Color("#123456"))
            Rectangle.parse(
                {
                    'x': 1,
                    'y': 2,
                    'height': 2,
                    'width': 3,
                    'color': "(0, 255, 0)"
                }, {}, 1)
Exemplo n.º 27
0
 def draw_if_next(x, y):
     Rectangle.draw_rectangle_yellow(x, y)
     Rectangle.draw_rectangle_yellow(x + 30, y)
     Rectangle.draw_rectangle_yellow(x, y - 30)
     Rectangle.draw_rectangle_yellow(x + 30, y - 30)
Exemplo n.º 28
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())
Exemplo n.º 29
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()))
Exemplo n.º 30
0
 def draw_if_next(x, y):
     Rectangle.draw_rectangle_light_blue(x + 30, y)
     Rectangle.draw_rectangle_light_blue(x + 60, y)
     Rectangle.draw_rectangle_light_blue(x, y - 30)
     Rectangle.draw_rectangle_light_blue(x + 30, y - 30)