hbui
2024-07-15 f736ce6b3b90d11bac59244c89f54c8528bd27d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest
 
from turtlegeo.PolygonDrawer import PolygonDrawer
 
class MotionRedording:
    def __init__(self):
        self._motion = []
        self._heading = 60
 
    def heading(self):
        self._motion.append("heading")
        return self._heading
 
    def teleport(self, x, y):
        self._motion.append(f"teleport:{x},{y}")
 
    def forward(self, length):
        self._motion.append(f"forward:{length}")
        pass
 
    def left(self, degree):
        self._motion.append(f"left:{degree}")
        pass
 
    def setheading(self, head):
        self._motion.append(f"setheading:{head}")
        pass
 
    def motion(self):
        return self._motion
 
 
class PolygonDrawerTestCase(unittest.TestCase):
    def test_triangle(self):
        dummyTurtle = MotionRedording()
        t = PolygonDrawer(dummyTurtle)
        t.triangle(30, 3, 4)
        # print(dummyTurtle.motion())
        result = dummyTurtle.motion()
        self.assertEqual(9, len(result))
        forward = [step for step in result if step.startswith("forward")]
        self.assertEqual(3, len(forward))
        pass
 
 
if __name__ == '__main__':
    unittest.main()