This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
test.py
61 lines (40 loc) · 2.21 KB
/
test.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
56
57
58
59
60
61
import unittest
class RobotControllortTestCase(unittest.TestCase):
"""Test for Robot Controller project"""
def test_cal_barriers(self):
self.assertEqual(number_of_barriers_row1, 7)
self.assertEqual(number_of_barriers_col3, 3)
def test_cal_loc_map(self):
self.assertEqual(loc_map["start"], (0, 8))
self.assertEqual(loc_map["destination"], (0, 0))
def test_is_move_valid(self):
self.assertEqual(is_move_valid(env_data, (0, 0), 'u'), False)
self.assertEqual(is_move_valid(env_data, (0, 0), 'l'), False)
self.assertEqual(is_move_valid(env_data, (4, 0), 'd'), False)
self.assertEqual(is_move_valid(env_data, (0, 8), 'r'), False)
self.assertEqual(is_move_valid(env_data, (0, 0), 'r'), False)
self.assertEqual(is_move_valid(env_data, (1, 0), 'd'), False)
self.assertEqual(is_move_valid(env_data, (1, 7), 'd'), True)
self.assertEqual(is_move_valid(env_data, (3, 5), 'r'), True)
self.assertEqual(is_move_valid(env_data, (1, 0), 'u'), True)
def test_is_move_valid_special(self):
self.assertEqual(is_move_valid_special((0, 0), 'u'), False)
self.assertEqual(is_move_valid_special((0, 0), 'l'), False)
self.assertEqual(is_move_valid_special((4, 0), 'd'), False)
self.assertEqual(is_move_valid_special((0, 8), 'r'), False)
self.assertEqual(is_move_valid_special((0, 0), 'r'), False)
self.assertEqual(is_move_valid_special((1, 0), 'd'), False)
self.assertEqual(is_move_valid_special((1, 7), 'd'), True)
self.assertEqual(is_move_valid_special((3, 5), 'r'), True)
self.assertEqual(is_move_valid_special((1, 0), 'u'), True)
def test_valid_actions(self):
self.assertEqual(valid_actions(env_data, (0, 8)), ['d'])
result_list = valid_actions(env_data, (1, 0))
self.assertTrue(['u', 'r'] == result_list or ['r', 'u'] == result_list)
def test_move_robot(self):
self.assertEqual(move_robot((1, 0), 'u'), (0, 0))
self.assertEqual(move_robot((0, 8), 'd'), (1, 8))
self.assertEqual(move_robot((3, 3), 'l'), (3, 2))
self.assertEqual(move_robot((1, 0), 'r'), (1, 1))
if __name__ == '__main__':
unittest.main()