def test_list_shape_command(receiver: ReceiverMockup): command = ListShapeCommand(receiver) assert str(command) == 'ls' assert command == ListShapeCommand(receiver) command.execute() assert receiver.listed_shapes == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert command.listed == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] command.reverse() assert receiver.deleted_lines == len(command.listed) + 1 command = ListShapeCommand(receiver=receiver, x=123, y=321) assert str(command) == 'ls 123,321' assert command == ListShapeCommand(receiver=receiver, x=123, y=321) command.execute() assert receiver.listed_shapes == [ Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert command.listed == [ Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] command.reverse() assert receiver.deleted_lines == len(command.listed) + 1
def test_remove_shape_command(receiver: ReceiverMockup): command = RemoveShapeCommand(receiver=receiver, x=123, y=321) assert str(command) == 'remove 123,321' assert command == RemoveShapeCommand(receiver=receiver, x=123, y=321) command.execute() assert receiver.received == Point(123, 321) assert command._before_remove == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.removed == [ Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.deleted_lines == 0 command.reverse() assert receiver.received == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.deleted_lines == 1 command = RemoveShapeCommand(receiver=receiver, x=-1, y=-1) command.execute() assert receiver.removed == [] assert receiver.deleted_lines == 1 assert receiver.last_command_removed is True
def test_move_shape_command(receiver: ReceiverMockup): command = MoveShapeCommand(receiver=receiver, start_x=0, start_y=0, end_x=10, end_y=10) assert str(command) == 'move 0,0 10,10' assert command == MoveShapeCommand(receiver=receiver, start_x=0, start_y=0, end_x=10, end_y=10) command.execute() assert receiver.received == (Point(0, 0), Point(10, 10)) assert command._before_move == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.moved == [] assert receiver.deleted_lines == 1 assert receiver.last_command_removed is True command = MoveShapeCommand(receiver=receiver, start_x=10, start_y=10, end_x=0, end_y=0) command.execute() assert receiver.received == (Point(10, 10), Point(0, 0)) assert command._before_move == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.moved == [ Dot(start=Point(0, 0), color=Color(0, 0, 0)), Line(start=Point(113, 311), end=Point(0, 0), color=Color(0, 0, 0)) ] command.reverse() assert receiver.received == [ Dot(start=Point(10, 10), color=Color(0, 0, 0)), Line(start=Point(123, 321), end=Point(10, 10), color=Color(0, 0, 0)) ] assert receiver.deleted_lines == 1
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
def test_clear_command(receiver: ReceiverMockup): command = ClearCommand(receiver) assert str(command) == 'clear' assert command == ClearCommand(receiver) command.execute() assert receiver.restarted is True assert command.shapes == [ Line(Point(10, 10), Point(20, 20), Color(1, 2, 3)), Dot(Point(10, 10), Color(1, 2, 3)) ] command.reverse() assert receiver.deleted_lines == 1 assert receiver.received == [ Line(Point(10, 10), Point(20, 20), Color(1, 2, 3)), Dot(Point(10, 10), Color(1, 2, 3)) ]
def test_dot(shapes: Dict[str, Shape]): dot = shapes['dot'] assert dot.start == Point(10, 200000000) assert dot.color == Color(1, 2, 3) assert dot.get_props() == (10, 200000000) d = PrinterMockup() dot.print_to(d) assert d.result == 'Drawed a ' + str(dot) assert str(dot) == 'Dot at [10, 200000000] with Color(1, 2, 3, alpha=255)' assert dot == Dot(Point(10, 200000000), Color(1, 2, 3)) assert dot != Dot(Point(10, 200000000), Color(1, 2, 4)) assert dot.contains(Point(10, 200000000)) is True assert dot.contains(Point(11, 200000000), divergence=True) is True assert dot.contains(Point(11, 200000000)) is False assert dot.contains(Point(13, 200000000), divergence=True) is False new_dot = dot.move(Point(10, 200000000), Point(0, 0)) assert dot.start == Point(10, 200000000) assert new_dot == Dot(Point(0, 0), dot.color)
def test_dot_command(receiver: ReceiverMockup): command = PrintDotCommand(receiver=receiver, x=0, y=-12, color=(1, 2, 3)) assert str(command) == 'dot 0,-12 rgb(1,2,3)' assert command == PrintDotCommand(receiver=receiver, x=0, y=-12, color=(1, 2, 3)) command.execute() assert receiver.received == Dot(start=Point(0, -12), color=Color(1, 2, 3)) command.reverse() assert receiver.received is None assert receiver.deleted_lines == 2
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
def __init__(self): self.shapes = [ Dot(Point(10, 10), Color(0, 0, 0)), Line(Point(123, 321), Point(10, 10), Color(0, 0, 0)) ] self.received = None self.moved = [] self.removed = [] self.listed_shapes = None self.last_command_removed = None self.printed = '' self.deleted_lines = 0 self.restarted = False self.saved = None self.loaded = None self.quited = False
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)) }
def __init__(self, receiver, x: int, y: int, color: tuple): super().__init__(receiver) self.shape = Dot(Point(x, y), Color(*color))
def print_dot(self, dot: Dot): painter = self._prepare_painter(dot.color) pen = QPen(painter.brush(), 5) pen.setColor(QColor(*dot.color)) painter.setPen(pen) painter.drawPoint(*dot.get_props())
def shapes_at(self, point: Point = None) -> List[Shape]: return [ Line(Point(10, 10), Point(20, 20), Color(1, 2, 3)), Dot(Point(10, 10), Color(1, 2, 3)) ]