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()
|