def test_to_command_returns_empty_list_for_blank(self):
        test_gcode_line = ""
        command_reader = GCodeCommandReader()

        actual = command_reader.to_command(test_gcode_line)

        self.assertEquals([], actual)
    def test_to_command_returns_empty_list_for_blank(self):
        test_gcode_line = ""
        command_reader = GCodeCommandReader()

        actual = command_reader.to_command(test_gcode_line)

        self.assertEquals([], actual)
    def test_to_command_uses_default_if_speed_never_specified(self):
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_test)
        self.assertCommandsEqual(expected, actual)
    def test_to_command_uses_default_if_speed_never_specified(self):
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_test)
        self.assertCommandsEqual(expected, actual)
    def test_to_command_returns_empty_list_for_ignorable_codes(self):
        test_gcode_lines = [";Comment", "M101", "O NAME OF PROGRAM"]
        command_reader = GCodeCommandReader()

        actuals = [command_reader.to_command(line) for line in test_gcode_lines]

        self.assertEquals([[], [], []], actuals)
    def test_to_command_handles_vertical_movement(self):
        gcode_test = "G0 Z1.0 F6000 E0"
        command_reader = GCodeCommandReader()
        expected = [VerticalMove(0.0, 1.0, 100.0)]

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_returns_a_LateralDraw_given_move_with_extrude(self):
        gcode_line = "G1 X1.0 Y1.0 F6000 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_handles_unknown_sub_command(self):
        gcode_line = "G1 X1.0 Y1.0 F6000 E12 Q55"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100)]

        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_handles_unknown_sub_command(self):
        gcode_line = "G1 X1.0 Y1.0 F6000 E12 Q55"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100)]

        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_creates_move_if_E_not_specified(self):
        gcode_test = "G0 X1.0 Y1.0 F6000"
        command_reader = GCodeCommandReader()
        expected = [LateralMove([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_handles_vertical_movement(self):
        gcode_test = "G0 Z1.0 F6000 E0"
        command_reader = GCodeCommandReader()
        expected = [VerticalMove(0.0, 1.0, 100.0)]

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_creates_move_if_E_not_specified(self):
        gcode_test = "G0 X1.0 Y1.0 F6000"
        command_reader = GCodeCommandReader()
        expected = [LateralMove([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_returns_a_LateralDraw_given_move_with_extrude(self):
        gcode_line = "G1 X1.0 Y1.0 F6000 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_does_not_permit_handles_vertical_down_movement(self):
        gcode_setup = "G0 Z1.0 F6000 E0"
        gcode_test = "G0 Z0.1 F6000 E0"
        command_reader = GCodeCommandReader()

        command_reader.to_command(gcode_setup)

        with self.assertRaises(Exception):
            command_reader.to_command(gcode_test)
    def test_to_command_returns_a_LateralDraw_when_0(self):
        gcode_setup = "G1 X0.0 Y0.0 F6000 E12"
        gcode_line = "G1 X-8.98 Y0.00 E1.71364"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [-8.98, 0.0], 100.0)]
        command_reader.to_command(gcode_setup)
        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_returns_a_LateralDraw_when_0(self):
        gcode_setup = "G1 X0.0 Y0.0 F6000 E12"
        gcode_line = "G1 X-8.98 Y0.00 E1.71364"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([0.0, 0.0], [-8.98, 0.0], 100.0)]
        command_reader.to_command(gcode_setup)
        actual = command_reader.to_command(gcode_line)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_returns_empty_list_for_ignorable_codes(self):
        test_gcode_lines = [";Comment", "M101", "O NAME OF PROGRAM"]
        command_reader = GCodeCommandReader()

        actuals = [
            command_reader.to_command(line) for line in test_gcode_lines
        ]

        self.assertEquals([[], [], []], actuals)
    def test_to_command_remembers_last_speed_if_none_specified(self):
        gcode_setup = "G1 X1.0 Y1.0 F6000 E12"
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([1.0, 1.0], [1.0, 1.0], 100.0)]

        command_reader.to_command(gcode_setup)
        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_remembers_last_speed_if_none_specified(self):
        gcode_setup = "G1 X1.0 Y1.0 F6000 E12"
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected = [LateralDraw([1.0, 1.0], [1.0, 1.0], 100.0)]

        command_reader.to_command(gcode_setup)
        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_remembers_last_speed_if_only_specified(self):
        gcode_setup = "G1 F6000"
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected_verify = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        setup = command_reader.to_command(gcode_setup)
        verify = command_reader.to_command(gcode_test)

        self.assertEqual([], setup)
        self.assertCommandsEqual(expected_verify, verify)
    def test_to_command_remembers_last_speed_if_only_specified(self):
        gcode_setup = "G1 F6000"
        gcode_test = "G1 X1.0 Y1.0 E12"
        command_reader = GCodeCommandReader()
        expected_verify = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]

        setup = command_reader.to_command(gcode_setup)
        verify = command_reader.to_command(gcode_test)

        self.assertEqual([], setup)
        self.assertCommandsEqual(expected_verify, verify)
    def test_to_command_handles_units(self):
        gcode_metric = "G21"
        gcode_metric_line = "G1 X1.0 Y1.0 F6000 E12"
        gcode_feet = "G20"
        gcode_feet_line = "G1 X1.0 Y1.0 F6000 E12"
        command_reader = GCodeCommandReader()
        expected_metric = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]
        expected_feet = [LateralDraw([1.0, 1.0], [25.4, 25.4], 2540.0)]

        command_reader.to_command(gcode_metric)
        self.assertCommandsEqual(expected_metric,
                                 command_reader.to_command(gcode_metric_line))

        command_reader.to_command(gcode_feet)
        self.assertCommandsEqual(expected_feet,
                                 command_reader.to_command(gcode_feet_line))
    def test_to_command_does_not_permit_handles_vertical_down_movement(self):
        gcode_setup = "G0 Z1.0 F6000 E0"
        gcode_test = "G0 Z0.1 F6000 E0"
        command_reader = GCodeCommandReader()

        command_reader.to_command(gcode_setup)

        with self.assertRaises(Exception):
            command_reader.to_command(gcode_test)
    def test_to_command_handles_units(self):
        gcode_metric = "G21"
        gcode_metric_line = "G1 X1.0 Y1.0 F6000 E12"
        gcode_feet = "G20"
        gcode_feet_line = "G1 X1.0 Y1.0 F6000 E12"
        command_reader = GCodeCommandReader()
        expected_metric = [LateralDraw([0.0, 0.0], [1.0, 1.0], 100.0)]
        expected_feet = [LateralDraw([1.0, 1.0], [25.4, 25.4], 2540.0)]

        command_reader.to_command(gcode_metric)
        self.assertCommandsEqual(expected_metric, command_reader.to_command(gcode_metric_line))

        command_reader.to_command(gcode_feet)
        self.assertCommandsEqual(expected_feet, command_reader.to_command(gcode_feet_line))
    def test_vertically_diagonal_move_are_made_moves_and_lateral_moves(self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.5 Y0.5 F6000"
        gcode_test = "G0 X0.7 Y0.7 Z0.5 F6000"
        command_reader = GCodeCommandReader()
        expected = [
            VerticalMove(0.2, 0.5, 100.0),
            LateralMove([0.5, 0.5], [0.7, 0.7], 100.0),
        ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        self.assertCommandsEqual(expected,
                                 command_reader.to_command(gcode_test))
    def test_to_command_can_scale_when_scale_provided(self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.0 Y0.0 F6000"
        gcode_test = "G0 X1.0 Y1.0 Z0.3 F6000"
        command_reader = GCodeCommandReader(scale=0.1)
        expected = [
            VerticalMove(0.02, 0.03, 100.0),
            LateralMove([0.0, 0.0], [0.1, 0.1], 100.0),
        ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        self.assertCommandsEqual(expected,
                                 command_reader.to_command(gcode_test))
    def test_to_command_can_scale_when_scale_provided(self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.0 Y0.0 F6000"
        gcode_test = "G0 X1.0 Y1.0 Z0.3 F6000"
        command_reader = GCodeCommandReader(scale=0.1)
        expected = [
            VerticalMove(0.02, 0.03, 100.0),
            LateralMove([0.0, 0.0], [0.1, 0.1], 100.0),
            ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        self.assertCommandsEqual(expected, command_reader.to_command(gcode_test))
    def test_vertically_diagonal_move_are_made_moves_and_lateral_moves(self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.5 Y0.5 F6000"
        gcode_test = "G0 X0.7 Y0.7 Z0.5 F6000"
        command_reader = GCodeCommandReader()
        expected = [
            VerticalMove(0.2, 0.5, 100.0),
            LateralMove([0.5, 0.5], [0.7, 0.7], 100.0),
            ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        self.assertCommandsEqual(expected, command_reader.to_command(gcode_test))
    def test_to_command_allows_vertical_write_provide_layer_increment_specified(
            self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.5 Y0.5 F6000"
        gcode_test = "G0 Z0.5 F6000 E1"
        command_reader = GCodeCommandReader()
        expected = [
            VerticalMove(0.2, 0.3, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
            VerticalMove(0.3, 0.4, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
            VerticalMove(0.4, 0.5, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
        ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
    def test_to_command_allows_vertical_write_provide_layer_increment_specified(self):
        gcode_setup1 = "G0 Z0.1 F6000 E0"
        gcode_setup2 = "G0 Z0.2 F6000 E0"
        gcode_setup3 = "G0 X0.5 Y0.5 F6000"
        gcode_test = "G0 Z0.5 F6000 E1"
        command_reader = GCodeCommandReader()
        expected = [
            VerticalMove(0.2, 0.3, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
            VerticalMove(0.3, 0.4, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
            VerticalMove(0.4, 0.5, 100.0),
            LateralDraw([0.5, 0.5], [0.5, 0.5], 100.0),
            ]

        command_reader.to_command(gcode_setup1)
        command_reader.to_command(gcode_setup2)
        command_reader.to_command(gcode_setup3)

        actual = command_reader.to_command(gcode_test)

        self.assertCommandsEqual(expected, actual)
 def test_unsupported_codes_raises_exception(self):
     test_gcode_line = "P01 X123.0 C7"
     command_reader = GCodeCommandReader()
     with self.assertRaises(Exception):
         command_reader.to_command(test_gcode_line)
 def test_unsupported_codes_raises_exception(self):
     test_gcode_line = "P01 X123.0 C7"
     command_reader = GCodeCommandReader()
     with self.assertRaises(Exception):
         command_reader.to_command(test_gcode_line)