-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTurtleWorld_test.py
More file actions
59 lines (46 loc) · 1.36 KB
/
TurtleWorld_test.py
File metadata and controls
59 lines (46 loc) · 1.36 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
"""This module is part of Swampy, a suite of programs available from
allendowney.com/swampy.
Copyright 2010 Allen B. Downey
Distributed under the GNU General Public License at gnu.org/licenses/gpl.html.
"""
import unittest
import TurtleWorld
class Tests(unittest.TestCase):
def test_turtle_world(self):
tw = TurtleWorld.TurtleWorld(interactive=True)
tw.setup_run()
tw.delay = 0.01
control = tw.make_turtle()
control.set_color('magenta')
control.move_turtle(-1)
tw.clear()
tw.quit()
def test_turtle(self):
tw = TurtleWorld.TurtleWorld()
t = TurtleWorld.Turtle()
t.delay = 0.01
t.step()
t.bk(10)
t.rt(10)
t.lt(-10)
t.pu()
t.pd()
t.set_color('papaya whip')
t.set_pen_color('yellow')
TurtleWorld.fd(t, 10)
TurtleWorld.bk(t, 10)
TurtleWorld.lt(t, 10)
TurtleWorld.rt(t, 10)
TurtleWorld.pu(t)
TurtleWorld.pd(t)
TurtleWorld.set_color(t, 'cyan')
TurtleWorld.set_pen_color(t, 'magenta')
x = t.get_x()
self.assertAlmostEquals(x, -9.0)
y = t.get_y()
self.assertAlmostEquals(y, 0.0)
heading = t.get_heading()
self.assertAlmostEquals(heading, -20)
tw.quit()
if __name__ == '__main__':
unittest.main()