def test_not_equals(receiver: ReceiverMockup): assert ( PrintDotCommand(receiver, 0, 0, (0, 0, 0)) != PrintLineCommand( receiver, 0, 0, 0, 0, (0, 0, 0)) != PrintRectCommand( receiver, 0, 0, (0, 0, 0), PointsRectFactory, end_x=0, end_y=0) != PrintCircleCommand( receiver, 0, 0, (0, 0, 0), PointsCircleFactory, end_x=0, end_y=0)) assert (PrintDotCommand(receiver, 0, 0, (0, 0, 0)) != PrintLineCommand( receiver, 0, 0, 0, 0, (0, 0, 0) ) != PrintRectCommand( receiver, 0, 0, (0, 0, 0), DimensionsRectFactory, width=0, height=0) != PrintCircleCommand( receiver, 0, 0, (0, 0, 0), DimensionsCircleFactory, radius=0)) assert (PrintDotCommand(receiver, 0, 0, (0, 0, 0)) != PrintDotCommand( receiver, 1, 0, (0, 0, 0))) assert (PrintLineCommand(receiver, 0, 0, 0, 0, (0, 0, 0)) != PrintLineCommand( receiver, 0, 0, 1, 0, (0, 0, 0))) assert (PrintRectCommand( receiver, 0, 0, (0, 0, 0), PointsRectFactory, end_x=0, end_y=0) != PrintRectCommand( receiver, 0, 0, (0, 0, 0), PointsRectFactory, end_x=0, end_y=1)) assert (PrintRectCommand( receiver, 0, 0, (0, 0, 0), DimensionsRectFactory, width=0, height=0 ) != PrintRectCommand( receiver, 0, 1, (0, 0, 0), DimensionsRectFactory, width=0, height=0)) assert (PrintCircleCommand( receiver, 0, 0, (0, 0, 0), PointsCircleFactory, end_x=0, end_y=0) != PrintCircleCommand( receiver, 0, 1, (0, 0, 0), PointsCircleFactory, end_x=0, end_y=0)) assert (PrintCircleCommand( receiver, 0, 0, (0, 0, 0), DimensionsCircleFactory, radius=0) != PrintCircleCommand( receiver, 0, 1, (0, 0, 0), DimensionsCircleFactory, radius=0))
def test_dot_parser(controller: Controller, cli_parser: CliParser): """ :return: """ # Test invalid inputs invalid_inputs = [ "dot 10,-20", "dot +10,20", "dot 10.20", "dot 10 20", "dot10,20", "dot 10,20 30,40", "dott 10,20", "dot something", "dot 10,20 rgb(0,0,-1)", "dot 10,20 30,40 rgb(0,0,0", "dot 10,20 rgb 0,0,0", "dot 10,20 rgb(0,1)", "dot 10,20rgb(0,1,2)", "dot 10,20 rgb(1a,2,3)", "dot 10,20,rgb(0,2,3)", "dot 10,20 rgb(256,0,1)", "dot 10,20 rgb(2.0.1)", "dot 10,20 rgb(123)" ] for cli_input in invalid_inputs: command = cli_parser.parse_input(cli_input) assert command == InvalidCommand(controller) # Test valid inputs valid_inputs = [ ("dot 10, 20", PrintDotCommand(controller, 10, 20, (0, 0, 0))), ("dot -10 ,+20", PrintDotCommand(controller, -10, +20, (0, 0, 0))), (" dot -5,-5 ", PrintDotCommand(controller, -5, -5, (0, 0, 0))), ("dot 10,20 rgb (10,20,30) ", PrintDotCommand(controller, 10, 20, (10, 20, 30))), ("dot -10 , -20 rgb ( 0 , 0, 0 ) ", PrintDotCommand(controller, -10, -20, (0, 0, 0))) ] for cli_input, expected in valid_inputs: command = cli_parser.parse_input(cli_input) assert command == expected
def shape_commands( controller: Controller ) -> Tuple[Command, Command, Command, Command, Command]: c1 = PrintDotCommand(receiver=controller, x=10, y=200000000, color=(1, 2, 3)) c2 = PrintLineCommand(receiver=controller, start_x=1000, start_y=-1000, end_x=0, end_y=-1000, color=(0, 0, 0)) c3 = PrintPolylineCommand(receiver=controller, points=[(10, 10), (20, 20), (30, 10)], color=(48, 210, 111)) c4 = PrintRectCommand(receiver=controller, start_x=0, start_y=0, end_x=1, end_y=50000, color=(255, 255, 255)) c5 = PrintCircleCommand(receiver=controller, start_x=12345, start_y=54321, end_x=13344, end_y=54321, color=(123, 255, 0)) return c1, c2, c3, c4, c5
def test_dot_brush(controller: ControllerMockup): b1 = DotShapeBrush() b2 = DotShapeBrush() assert b1 == b2 assert str(b1) == str(b2) == 'Dot' b1.mouse_move(controller, 10, 20, Qt.LeftButton) assert controller.command == PrintDotCommand(receiver=controller, x=10, y=20, color=(0, 0, 0)) b1.mouse_press(controller, 123, 321, Qt.LeftButton) assert controller.command == PrintDotCommand(receiver=controller, x=123, y=321, color=(0, 0, 0))
def test_mouse_move_event(canvas: Canvas): assert canvas.brush == MoveShapeBrush() assert canvas.cursor() == Qt.ArrowCursor canvas.mouseMoveEvent(EventMockup) assert (canvas._controller.command is None) canvas.set_brush(DotShapeBrush()) canvas.mouseMoveEvent(EventMockup) assert (canvas._controller.command == PrintDotCommand( canvas._controller, EventMockup.x(), EventMockup.y(), (255, 255, 255))) assert canvas.cursor() == Qt.CrossCursor
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 parse_params(self, cli_input: str) -> ParseResult: point_result = PointParser().parse_point(cli_input) if point_result.is_successful(): abs_point = self.convert_points([point_result.get_match()]) point_x = abs_point[0].x point_y = abs_point[0].y # Parse color color_result = self.parse_color(point_result.get_remainder(), self.color_parser) if color_result.is_successful(): color = color_result.get_match() return Success( PrintDotCommand(self._controller, point_x, point_y, color), '') else: return Failure(color_result.get_expected(), point_result.get_remainder()) return Failure("dot <POINT>", cli_input)