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

Class InterpreterTests

tests/test_interpreter.py:18–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17
18class InterpreterTests(unittest.TestCase):
19 def setUp(self):
20 self.i = LSystemInterpeter("default", 1.0, 90)
21
22 def test_forward(self):
23 commands = io.StringIO("FG")
24 expected = [LineString([(0, 0, 0), (0, 0, 2)])]
25 tokens = self.i.tokenize(commands)
26 lines = list(self.i.interpret(tokens))
27 self.assertListEqual(lines, expected)
28
29 def test_forward_no_draw(self):
30 commands = io.StringIO("fGF")
31 expected = [LineString([(0, 0, 1), (0, 0, 3)])]
32 tokens = self.i.tokenize(commands)
33 lines = list(self.i.interpret(tokens))
34 self.assertListEqual(lines, expected)
35
36 def test_forward_no_draw_cuts_line(self):
37 commands = io.StringIO("FfF")
38 expected = [
39 LineString([(0, 0, 0), (0, 0, 1)]),
40 LineString([(0, 0, 2), (0, 0, 3)]),
41 ]
42 tokens = self.i.tokenize(commands)
43 lines = list(self.i.interpret(tokens))
44 self.assertListEqual(lines, expected)
45
46 def test_yaw(self):
47 commands = io.StringIO("F+F-F")
48 expected = [LineString([(0, 0, 0), (0, 0, 1), (0, -1, 1), (0, -1, 2)])]
49 tokens = self.i.tokenize(commands)
50 lines = list(self.i.interpret(tokens))
51 self.assertEqual(len(lines), len(expected))
52 for actual, desired in zip(lines, expected):
53 self.assertTrue(actual.equals_exact(desired, tolerance=1e-6))
54
55 def test_draw_no_draw(self):
56 commands = io.StringIO("dF+FDFF")
57 expected = [LineString([(0, -1, 1), (0, -3, 1)])]
58 tokens = self.i.tokenize(commands)
59 lines = list(self.i.interpret(tokens))
60 self.assertEqual(len(lines), len(expected))
61 for actual, desired in zip(lines, expected):
62 self.assertTrue(actual.equals_exact(desired, tolerance=1e-6))
63
64 def test_draw_no_draw_cuts_line(self):
65 commands = io.StringIO("dF+DFdFDF")
66 expected = [
67 LineString([(0, 0, 1), (0, -1, 1)]),
68 LineString([(0, -2, 1), (0, -3, 1)]),
69 ]
70 tokens = self.i.tokenize(commands)
71 lines = list(self.i.interpret(tokens))
72 self.assertEqual(len(lines), len(expected))
73 for actual, desired in zip(lines, expected):
74 self.assertTrue(
75 actual.equals_exact(desired, tolerance=1e-6),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected