def test_circle(shapes: Dict[str, Shape]): circle: Circle = shapes['circle'] assert circle.start == Point(12345, 54321) assert circle.radius == 999 assert circle.color == Color(123, 255, 0) assert circle.get_props() == (12345, 54321, 999) d = PrinterMockup() circle.print_to(d) assert d.result == 'Drawed a ' + str(circle) assert str(circle) == 'Circle centered at [12345, 54321] with radius 999 with Color(123, 255, 0, alpha=255)' assert circle == Circle(Point(12345, 54321), 999, Color(123, 255, 0)) assert circle != Circle(Point(12345, 54321), 999, Color(123, 255, 1)) assert circle.contains(Point(12345, 54321)) is True assert circle.contains(Point(13344, 54321)) is True assert circle.contains(Point(12345, 53322)) is True assert circle.contains(Point(12344, 53322)) is False assert circle.contains(Point(13344, 54322)) is False # Vertical move new_circle = circle.move(Point(13344, 54321), Point(13344, 0)) assert circle.start == Point(12345, 54321) assert new_circle == Circle(Point(12345, 0), circle.radius, circle.color) # Horizontal move new_circle = circle.move(Point(12345, 53322), Point(0, 53322)) assert circle.start == Point(12345, 54321) assert new_circle == Circle(Point(0, 54321), circle.radius, circle.color) # Diagonal move new_circle = circle.move(Point(13344, 54321), Point(0, 0)) assert circle.start == Point(12345, 54321) assert new_circle == Circle(Point(-999, 0), circle.radius, circle.color)
def get_shape(start_x: int, start_y: int, color: Tuple[int, int, int], **kwargs) -> Circle: radius = kwargs['radius'] center = (start_x, start_y) circle = Circle(Point(*center), int(radius), Color(*color)) return circle
def test_circle_command_with_points(receiver: ReceiverMockup): command = PrintCircleCommand(receiver=receiver, start_x=0, start_y=0, color=(0, 0, 0), circle_factory=PointsCircleFactory, end_x=100, end_y=100) assert str(command) == 'circle 0,0 141 rgb(0,0,0)' assert (command == PrintCircleCommand(receiver=receiver, start_x=0, start_y=0, color=(0, 0, 0), circle_factory=PointsCircleFactory, end_x=100, end_y=100)) command.execute() assert receiver.received == Circle(center=Point(0, 0), radius=141, color=Color(0, 0, 0)) command.reverse() assert receiver.received is None assert receiver.deleted_lines == 2
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 get_shape(start_x: int, start_y: int, color: Tuple[int, int, int], **kwargs) -> Circle: end_x = kwargs['end_x'] end_y = kwargs['end_y'] center = (start_x, start_y) radius = distance(Point(*center), Point(end_x, end_y)) circle = Circle(Point(*center), int(radius), Color(*color)) return circle
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 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 test_dimensions_circle_factory(): circle = DimensionsCircleFactory.get_shape(0, 0, (0, 20, 40), radius=141) assert circle == Circle(Point(0, 0), 141, Color(0, 20, 40))
def test_points_circle_factory(): circle = PointsCircleFactory.get_shape(0, 0, (0, 20, 40), end_x=100, end_y=100) assert circle == Circle(Point(0, 0), 141, Color(0, 20, 40))