MCPcopy Create free account
hub / github.com/Notgnoshi/generative / TurtleTests

Class TurtleTests

tests/test_turtle.py:10–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class TurtleTests(unittest.TestCase):
11 def test_initial_position(self):
12 turtle = Turtle()
13 assert_allclose(turtle.position, (0, 0, 0))
14 # Provide tuple, list, np.ndarray
15 turtle = Turtle(position=(1, 1, 1))
16 assert_allclose(turtle.position, (1, 1, 1))
17
18 turtle = Turtle(position=[2, 2, 2])
19 assert_allclose(turtle.position, (2, 2, 2))
20
21 turtle = Turtle(position=np.array([3, 3, 3]))
22 assert_allclose(turtle.position, (3, 3, 3))
23
24 def test_initial_rotation(self):
25 turtle = Turtle()
26 assert_allclose(turtle.rotation.as_matrix(), np.eye(3))
27
28 # A rotation 180 degrees about the global x axis should flip both the y and z axes.
29 rotation = Rotation.from_euler("x", [np.pi])
30 expected = [[1, 0, 0], [0, -1, 0], [0, 0, -1]]
31 turtle = Turtle(rotation=rotation)
32 # There's a little bit of numerical instability in the works.
33 assert_allclose(turtle.rotation.as_matrix(), [expected], atol=1e-15)
34
35 def test_forward(self):
36 turtle = Turtle()
37 assert_allclose(turtle.position, (0, 0, 0))
38 turtle.forward()
39 assert_allclose(turtle.position, (0, 0, 1))
40 turtle.forward(2)
41 assert_allclose(turtle.position, (0, 0, 3))
42
43 def test_rotated_forward(self):
44 # Apparently this rotates CW
45 rotation = Rotation.from_euler("y", [np.pi / 2])
46 turtle = Turtle(rotation=rotation)
47 turtle.forward(2)
48 assert_allclose(turtle.position, (2, 0, 0), atol=1e-15)
49
50 def test_roll(self):
51 # Roll is about the longitudinal axis, so roll() + forward() won't change direction.
52 turtle = Turtle()
53 assert_allclose(turtle.position, (0, 0, 0))
54 turtle.roll(45)
55 turtle.forward()
56 assert_allclose(turtle.position, (0, 0, 1))
57 turtle.yaw(45)
58 turtle.forward()
59 assert_allclose(turtle.position, (1 / 2, -1 / 2, 1 + np.sqrt(2) / 2))
60
61 def test_pitch(self):
62 turtle = Turtle()
63 turtle.pitch(45)
64 turtle.forward()
65 assert_allclose(turtle.position, (np.sqrt(2) / 2, 0, np.sqrt(2) / 2))
66 turtle.pitch(45)
67 turtle.forward()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected