-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovement_unit_tests.py
More file actions
180 lines (138 loc) · 6.19 KB
/
movement_unit_tests.py
File metadata and controls
180 lines (138 loc) · 6.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import unittest
import time
from test_support.movement import MovementManager
import sys
def user_accepts(question):
val = None
while val not in ['Y', 'y', 'N', 'n']:
val = raw_input(question + '( Y/n ) ')
if val in ['N', 'n']:
return False
else:
return True
def print_test_case_name(function_name):
banner = '\nRunning test case %s ' % function_name
print banner
class TestBase(unittest.TestCase):
def setUp(self):
self.movement_manager = MovementManager()
def runTest(self):
raise ValueError('test not implemented')
class StraightFast(TestBase):
def runTest(self):
if not user_accepts('Next test: Fast drive straight and back. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_linear_velocity(0.75)
# move forward 1 meter then backward
self.movement_manager.move_straight(2)
time.sleep(1)
self.movement_manager.move_straight(-2)
time.sleep(1)
if not user_accepts('did the robot move forward and backward equal distance of 2 meters and the same speed?'):
raise ValueError('FastSpeedStraightTestError')
class StraightModerate(TestBase):
def runTest(self):
if not user_accepts('Next test: Medium drive straight and back. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_linear_velocity(0.5)
# move forward 1 meter then backward
self.movement_manager.move_straight(2)
time.sleep(1)
self.movement_manager.move_straight(-2)
time.sleep(1)
if not user_accepts('did the robot move forward and backward equal distance of 2 meters and the same speed?'):
raise ValueError('ModerateSpeedStraightTestError')
class StraightSlow(TestBase):
def runTest(self):
if not user_accepts('Next test: Slow drive straight and back. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_linear_velocity(0.25)
# move forward 1 meter then backward
self.movement_manager.move_straight(2)
time.sleep(1)
self.movement_manager.move_straight(-2)
time.sleep(1)
if not user_accepts('did the robot move forward and backward equal distance of 2 meters and the same speed?'):
raise ValueError('SlowSpeedStraightTestError')
class RotateClockwiseFast(TestBase):
def runTest(self):
if not user_accepts('Next test: Fast Right turn. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(.75)
self.movement_manager.turn(-6.28)
time.sleep(1)
if not user_accepts('did the robot move 360 degrees (+/-) 45?'):
raise ValueError('FastClockwiseTurnError')
class RotateClockwiseSlow(TestBase):
def runTest(self):
if not user_accepts('Next test: Slow Right turn. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(.628)
self.movement_manager.turn(-6.28)
time.sleep(1)
if not user_accepts('did the robot move 360 degrees (+/-) 45?'):
raise ValueError('SlowClockwiseTurnError')
class RotateAnticlockwiseFast(TestBase):
def runTest(self):
if not user_accepts('Next test: Fast Left turn. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(0.75)
self.movement_manager.turn(6.28)
time.sleep(1)
if not user_accepts('did the robot move 360 degrees (+/-) 45?'):
raise ValueError('FastAntiClockwiseTurnError')
class RotateAnticlockwiseSlow(TestBase):
def runTest(self):
if not user_accepts('Next test: Slow Left turn. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(.628)
self.movement_manager.turn(6.28)
time.sleep(1)
if not user_accepts('did the robot move 360 degrees (+/-) 45?'):
raise ValueError('SlowAntiClockwiseTurnError')
class SquareClockwise(TestBase):
def runTest(self):
if not user_accepts('Next test: Clockwise Box. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(1.24)
self.movement_manager.set_max_linear_velocity(0.25)
for _ in range(4):
self.movement_manager.move_straight(1)
time.sleep(0.5)
self.movement_manager.turn(-0.25 * 6.28)
time.sleep(0.5)
if not user_accepts('did the robot drive in a shape resembling a square?'):
raise ValueError('ClockwiseSquareError')
class SquareAnticlockwise(TestBase):
def runTest(self):
if not user_accepts('Next test: Counter clockwise Box. Are you ready?'):
print 'continuing anyway'
self.movement_manager.set_max_angular_velocity(1.24)
self.movement_manager.set_max_linear_velocity(0.25)
for _ in range(4):
self.movement_manager.move_straight(1)
time.sleep(0.5)
self.movement_manager.turn(0.25 * 6.28)
time.sleep(0.5)
if not user_accepts('did the robot drive in a shape resembling a square?'):
raise ValueError('AntiClockwiseSquareError')
def get_test_suite():
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(StraightFast))
test_suite.addTest(unittest.makeSuite(StraightModerate))
test_suite.addTest(unittest.makeSuite(StraightSlow))
test_suite.addTest(unittest.makeSuite(RotateClockwiseFast))
test_suite.addTest(unittest.makeSuite(RotateClockwiseSlow))
test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseFast))
test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseSlow))
test_suite.addTest(unittest.makeSuite(SquareClockwise))
test_suite.addTest(unittest.makeSuite(SquareAnticlockwise))
return test_suite
def system_ready_for_test():
if not user_accepts('is the robot ready to be moved? (clear by 2 meters all directions?) '):
print 'exiting'
exit()
return True
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(get_test_suite())