def test_forward(self): output = StringIO() t = GcodeTurtle(fd=output) t.set_heading(0) t.forward(100) self.assertEqual(t.x, 0) self.assertEqual(t.y, 100)
def test_pen_down_does_not_retract_twice(self): output = StringIO() t = GcodeTurtle(fd=output) t.pen_up() prelude = output.getvalue() t.pen_down() t.pen_down() output_line = output.getvalue().replace(prelude, "") self.assertEqual(output_line, "G1 E1.000 F3000.000\r\n")
def test_setxyz_measures_distance(self): output = StringIO() t = GcodeTurtle(fd=output) prelude = output.getvalue() t.setxyz(20, 30, 40) start_e = t.e t.setxyz(30, 40, 50) stop_e = t.e distance = (stop_e - start_e) / t.extrusion_rate self.assertAlmostEqual(distance, 17.320508076)
def test_up(self): expected = u"G1 F1800.000 E0.00000\r\nG92 E0\r\nG1 Z0.700 F6000.000\r\nG1 E1.00000 F1800.000\r\nG1 F3000.000\r\n" output = StringIO() t = GcodeTurtle(fd=output) prelude = output.getvalue() t.up() output_line = output.getvalue() output_line = output_line.replace(prelude, "") self.assertEqual(output_line[-1], "\n") self.assertSequenceEqual(expected.split("\n"), output_line.split("\n"))
def test_pen_up(self): output = StringIO() t = GcodeTurtle(fd=output) prelude = output.getvalue() t.pen_up() output_line = output.getvalue().replace(prelude, "") self.assertEqual(output_line, "G1 E-1.000 F6000.000\r\n") prelude = output.getvalue() t.forward(10) output_line = output.getvalue().replace(prelude, "") self.assertNotEqual(output_line.split(" ")[-1][0], "E")
def test_setx(self): output = StringIO() t = GcodeTurtle(fd=output) prelude = output.getvalue() t.setx(20) output_line = output.getvalue() output_line = output_line.replace(prelude, "") output_line_parts = output_line.split(" ") self.assertEqual(len(output_line_parts), 3) self.assertEqual(output_line[-1], "\n") self.assertEqual(output_line.count("\n"), 1) self.assertEqual("G1", output_line_parts[0]) self.assertEqual("X20.000", output_line_parts[1]) self.assertEqual("E", output_line_parts[2][0])
def test_setxy(self): output = StringIO() t = GcodeTurtle(fd=output) prelude = output.getvalue() t.setxy(20, 30) output_line = output.getvalue() output_line = output_line.replace(prelude, "") output_line_parts = output_line.split(" ") self.assertEqual(len(output_line_parts), 4) self.assertEqual(output_line[-1], "\n") self.assertEqual(output_line.count("\n"), 1) self.assertEqual(output_line_parts[0], "G1") self.assertEqual(output_line_parts[1], "X20.000") self.assertEqual(output_line_parts[2], "Y30.000") self.assertEqual(output_line_parts[3][0], "E")
def test_right(self): output = StringIO() t = GcodeTurtle(fd=output) t.set_heading(0) t.right(30) t.forward(100) self.assertAlmostEqual(t.x, 50) self.assertAlmostEqual(t.y, 50 * (3 ** .5))