-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_robot.py
55 lines (42 loc) · 1.71 KB
/
test_robot.py
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
import unittest
from queue import Queue
from datetime import timedelta
from robot import *
class RoboTest(unittest.TestCase):
def test_odometry(self):
q_in = Queue()
q_out = Queue()
robot = Robot(q_in.get, q_out.put, term=ODOMETRY_ID)
dt = timedelta(microseconds = 200)
q_in.put((dt, ODOMETRY_ID, b'\x00\x00\x00\x00'))
robot.update()
self.assertEqual(robot.time, dt)
self.assertFalse(q_out.empty())
self.assertEqual(robot.odometry_left_raw, 0)
self.assertEqual(robot.odometry_right_raw, 0)
self.assertEqual(q_out.get(), (MOTOR_ID, b'\x00\x00'))
q_in.put((2*dt, ODOMETRY_ID, b'\x01\x01\x00\x00'))
robot.update()
self.assertFalse(q_out.empty())
self.assertEqual(robot.odometry_left_raw, 0)
self.assertEqual(robot.odometry_right_raw, 2)
self.assertEqual(q_out.get(), (MOTOR_ID, b'\x00\x00'))
def test_annotations(self):
q_in = Queue()
q_out = Queue()
q_annot = Queue()
robot = Robot(q_in.get, q_out.put, annot=q_annot.put)
robot.annot(b'TAG:turn_right_90deg:BEGIN')
self.assertEqual(q_annot.get_nowait(), b'TAG:turn_right_90deg:BEGIN')
def test_wait(self):
q_in = Queue()
q_out = Queue()
robot = Robot(q_in.get, q_out.put, term=ODOMETRY_ID)
dt = timedelta(seconds = 1)
for i in range(10):
q_in.put((i * dt, ODOMETRY_ID, b'\x00\x00\x00\x00'))
robot.wait(timedelta(seconds=3))
self.assertEqual(q_out.qsize(), 3 + 1) # extra update for undefined time
robot.wait(timedelta(seconds=3))
self.assertEqual(q_out.qsize(), 3 + 1 + 3)
# vim: expandtab sw=4 ts=4