Пример #1
0
def test_move_shapes(shapes_store: ShapesStore, shapes: Dict[str, Shape]):
    shapes_store.add_shapes(*shapes.values())

    res = shapes_store.move_shapes(Point(10, 10), Point(-100, 100))
    assert res['moved'] == [
        Polyline(Point(-100, 100),
                 Point(-90, 110),
                 Point(-80, 100),
                 color=Color(48, 210, 111))
    ]
    assert res['before_move'] == [*shapes.values()]
    assert len(shapes_store._controller.result) == 3

    shapes_store.add_shapes(
        Rectangle(Point(-10, 3490), 20, 20, Color(255, 255, 255)))
    # Getting the previously moved polyline back
    shapes_store.move_shapes(Point(-100, 100), Point(10, 10))
    res = shapes_store.move_shapes(Point(0, 3500), Point(-1000, -1000))
    assert res['moved'] == [
        Rectangle(Point(-1000, -4500), 1, 50000, Color(255, 255, 255)),
        Rectangle(Point(-1010, -1010), 20, 20, Color(255, 255, 255))
    ]
    assert res['before_move'] == [
        shapes['dot'], shapes['line'], shapes['rectangle'], shapes['circle'],
        Rectangle(Point(-10, 3490), 20, 20, Color(255, 255, 255)),
        shapes['polyline']
    ]
    assert len(shapes_store._controller.result) == 8
Пример #2
0
def test_remove_shapes_at(shapes_store: ShapesStore):
    r1 = Rectangle(Point(0, 0), 100, 100, QColor(0, 0, 0))
    r2 = Rectangle(Point(1, 1), 100, 100, QColor(0, 0, 0))
    c = Circle(Point(0, 0), 50, QColor(0, 0, 0))
    l1 = Line(Point(-10, 0), Point(10, 0), QColor(0, 0, 0))
    l2 = Line(Point(-10, 1), Point(10, 1), QColor(0, 0, 0))
    d = Dot(Point(0, 0), QColor(0, 0, 0))

    shapes_store.add_shapes(r1, r2, c, l1, l2, d)
    res = shapes_store.remove_shapes_at(Point(0, 0))

    assert res['before_remove'] == [r1, r2, c, l1, l2, d]
    assert res['removed'] == [r1, c, l1, d]
    assert shapes_store._shapes == [r2, l2]
    assert len(shapes_store._controller.result) == 2
Пример #3
0
def test_rect_command_with_dimensions(receiver: ReceiverMockup):
    command = PrintRectCommand(receiver=receiver,
                               start_x=50,
                               start_y=50,
                               color=(255, 255, 255),
                               rect_factory=DimensionsRectFactory,
                               width=50,
                               height=50)
    assert str(command) == 'rect 50,50 50 50 rgb(255,255,255)'
    assert (command == PrintRectCommand(receiver=receiver,
                                        start_x=50,
                                        start_y=50,
                                        color=(255, 255, 255),
                                        rect_factory=DimensionsRectFactory,
                                        width=50,
                                        height=50))

    command.execute()
    assert receiver.received == Rectangle(top_left=Point(50, 50),
                                          width=50,
                                          height=50,
                                          color=Color(255, 255, 255))

    command.reverse()
    assert receiver.received is None
    assert receiver.deleted_lines == 2
Пример #4
0
    def get_shape(start_x: int, start_y: int, color: Tuple[int, int, int],
                  **kwargs) -> Rectangle:
        width = kwargs['width']
        height = kwargs['height']

        rectangle = Rectangle(Point(start_x, start_y), width, height,
                              Color(*color))
        return rectangle
Пример #5
0
def test_shape_class_diff():
    abstract_shape = Shape(Point(100, 100), Color(100, 100, 100))
    dot = Dot(Point(100, 100), Color(100, 100, 100))
    line = Line(Point(100, 100), Point(100, 100), Color(100, 100, 100))
    polyline = Polyline(Point(100, 100), Point(100, 100), color=Color(100, 100, 100))
    rect = Rectangle(Point(100, 100), 100, 100, Color(100, 100, 100))
    circle = Circle(Point(100, 100), 100, Color(100, 100, 100))

    assert abstract_shape != dot != line != polyline != rect != circle
Пример #6
0
    def get_shape(start_x: int, start_y: int, color: Tuple[int, int, int],
                  **kwargs) -> Rectangle:
        end_x = kwargs['end_x']
        end_y = kwargs['end_y']

        width = abs(start_x - end_x)
        height = abs(start_y - end_y)
        rectangle = Rectangle(Point(min(start_x, end_x), min(start_y, end_y)),
                              width, height, Color(*color))
        return rectangle
Пример #7
0
def test_rectangle(shapes: Dict[str, Shape]):
    rect: Rectangle = shapes['rectangle']

    assert rect.start == Point(0, 0)
    assert rect.width == 1
    assert rect.height == 50000
    assert rect.color == Color(255, 255, 255)
    assert rect.get_props() == (0, 0, 1, 50000)

    d = PrinterMockup()
    rect.print_to(d)
    assert d.result == 'Drawed a ' + str(rect)
    
    assert str(rect) == '1x50000 rectangle with top-left corner at [0, 0] with Color(255, 255, 255, alpha=255)'
    assert rect == Rectangle(Point(0, 0), 1, 50000, Color(255, 255, 255))
    assert rect != Rectangle(Point(0, 0), -1, 50000, Color(255, 255, 255))
    assert rect.contains(Point(0, 0)) is True
    assert rect.contains(Point(1, 0)) is True
    assert rect.contains(Point(1, 50000)) is True
    assert rect.contains(Point(2, 0)) is False
    assert rect.contains(Point(0, 50001)) is False

    # Vertical move
    new_rect = rect.move(Point(1, 3500), Point(1, 0))
    assert rect.start == Point(0, 0)
    assert new_rect == Rectangle(Point(0, -3500), rect.width, rect.height, rect.color)

    # Horizontal move
    new_rect = rect.move(Point(0, 20), Point(20, 20))
    assert rect.start == Point(0, 0)
    assert new_rect == Rectangle(Point(20, 0), rect.width, rect.height, rect.color)

    # Diagonal move
    new_rect = rect.move(Point(1, 100), Point(20, 50))
    assert rect.start == Point(0, 0)
    assert new_rect == Rectangle(Point(19, -50), rect.width, rect.height, rect.color)
Пример #8
0
def shapes() -> Dict[str, Shape]:
    return {
        'dot':
        Dot(Point(10, 200000000), Color(1, 2, 3)),
        'line':
        Line(Point(1000, -1000), Point(0, -1000), Color(0, 0, 0)),
        'polyline':
        Polyline(Point(10, 10),
                 Point(20, 20),
                 Point(30, 10),
                 color=Color(48, 210, 111)),
        'rectangle':
        Rectangle(Point(0, 0), 1, 50000, Color(255, 255, 255)),
        'circle':
        Circle(Point(12345, 54321), 999, Color(123, 255, 0))
    }
Пример #9
0
def test_dimensions_rect_factory():
    rectangle = DimensionsRectFactory.get_shape(0,
                                                0, (0, 20, 40),
                                                width=10,
                                                height=20)
    assert rectangle == Rectangle(Point(0, 0), 10, 20, Color(0, 20, 40))
Пример #10
0
def test_points_rect_factory():
    rectangle = PointsRectFactory.get_shape(0,
                                            0, (0, 20, 40),
                                            end_x=10,
                                            end_y=20)
    assert rectangle == Rectangle(Point(0, 0), 10, 20, Color(0, 20, 40))
Пример #11
0
 def shapes_at(self, point: Point, divergence: bool = False) -> List[Shape]:
     shapes = [
         Line(Point(0, 0), Point(0, 10), Color(10, 20, 30)),
         Rectangle(Point(0, 5), 10, 10, Color(0, 0, 0))
     ]
     return [shape for shape in shapes if shape.contains(point)]
Пример #12
0
def test_move_shapes(controller: Controller, shape_commands, commands,
                     stream: io.StringIO, shapes: Dict[str, Shape]):
    for command in shape_commands:
        controller.execute_command(command)

    rect = Rectangle(top_left=Point(10, 10),
                     width=10,
                     height=10,
                     color=Color(10, 20, 30))
    moved_rect = Rectangle(top_left=Point(-10, 20),
                           width=rect.width,
                           height=rect.height,
                           color=rect.color)
    moved_polyline = Polyline(Point(-10, 20),
                              Point(0, 30),
                              Point(10, 20),
                              color=shapes['polyline'].color)
    rect_command = PrintRectCommand(receiver=controller,
                                    start_x=rect.start.x,
                                    start_y=rect.start.y,
                                    color=rect.color,
                                    rect_factory=DimensionsRectFactory,
                                    width=rect.width,
                                    height=rect.height)
    controller.execute_command(rect_command)

    controller.execute_command(commands[4])
    assert controller._shapes._shapes == [
        shapes['dot'], shapes['line'], shapes['rectangle'], shapes['circle'],
        moved_polyline, moved_rect
    ]
    assert controller._command_engine._undos == [
        *shape_commands, rect_command, commands[4]
    ]
    assert controller._gui._ui.history.toPlainText() == (
        f' > {shape_commands[0]}\n{shapes["dot"]}\n'
        f' > {shape_commands[1]}\n{shapes["line"]}\n'
        f' > {shape_commands[2]}\n{shapes["polyline"]}\n'
        f' > {shape_commands[3]}\n{shapes["rectangle"]}\n'
        f' > {shape_commands[4]}\n{shapes["circle"]}\n'
        f' > {rect_command}\n{rect}\n'
        f' > {commands[4]}')
    res = (
        f'{shapes["dot"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{rect}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{moved_polyline}\n{moved_rect}\n'
    )
    assert stream.getvalue() == res

    controller.execute_command(commands[5])
    assert controller._shapes._shapes == [
        shapes['dot'], shapes['line'], shapes['rectangle'], shapes['circle'],
        moved_polyline, moved_rect
    ]
    assert controller._command_engine._undos == [
        *shape_commands, rect_command, commands[4]
    ]
    assert controller._gui._ui.history.toPlainText() == (
        f' > {shape_commands[0]}\n{shapes["dot"]}\n'
        f' > {shape_commands[1]}\n{shapes["line"]}\n'
        f' > {shape_commands[2]}\n{shapes["polyline"]}\n'
        f' > {shape_commands[3]}\n{shapes["rectangle"]}\n'
        f' > {shape_commands[4]}\n{shapes["circle"]}\n'
        f' > {rect_command}\n{rect}\n'
        f' > {commands[4]}')
    res = (
        f'{shapes["dot"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["polyline"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{rect}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{moved_polyline}\n{moved_rect}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{moved_polyline}\n{moved_rect}\n'
        f'{shapes["dot"]}\n{shapes["line"]}\n{shapes["rectangle"]}\n{shapes["circle"]}\n{moved_polyline}\n{moved_rect}\n'
    )
    assert stream.getvalue() == res
Пример #13
0
 def print_rectangle(self, rect: Rectangle):
     painter = self._prepare_painter(rect.color)
     painter.drawRect(*rect.get_props())
Пример #14
0
 def shapes_at(self, point: Point, divergence: bool = False) -> List[Shape]:
     return [
         Line(Point(0, 0), Point(0, 10), Color(10, 20, 30)),
         Rectangle(Point(0, 5), 10, 10, Color(0, 0, 0))
     ]