-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
82 lines (69 loc) · 2.95 KB
/
tests.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import unittest
from cv_arena import wall_correction, trace_missing_path
class TestWallCorrection(unittest.TestCase):
def test_internal_walls(self):
'''
Test the function deals with walls at the center of the arena correctly
'''
self.assertEqual(wall_correction((17, 10)), (17, 11))
def test_outer_walls(self):
'''
Test the function deals with walls at the edge of the arena correctly
'''
self.assertEqual(wall_correction((5, 15)), (6, 15))
def test_corner_walls(self):
'''
Test the function deals with walls at the corner of the arena correctly, both at the inside of a corner and outside of a corner
'''
self.assertEqual(wall_correction((0, 0)), (1, 1), "Top left corner")
self.assertEqual(wall_correction((27, 0)), (26, 1), "Top right corner")
self.assertEqual(wall_correction((0, 30)),
(1, 29), "Bottom left corner")
self.assertEqual(wall_correction((27, 30)),
(26, 29), "Bottom right corner")
self.assertIn(wall_correction((5, 2)), [
(5, 1), (6, 1), (6, 2)], "ambiguous inner corner with 3 possible final locations")
def test_other_edge_cases(self):
'''
Other edge cases difficult to categorize
'''
pass
def test_illegal_input(self):
'''
test illegal inputs are correctly dealt with
'''
self.assertRaises(ValueError, wall_correction, (-1, -1))
class TestTracePath(unittest.TestCase):
def test_straight_path(self):
'''
test nodes that form a straight path are correctly dealt with
'''
correct_path_1 = [(1, 1), (2, 1), (3, 1)]
test_path_1 = trace_missing_path((1, 1), (3, 1))
print(test_path_1)
self.assertEqual(len(test_path_1),len(correct_path_1))
for i in range(len(correct_path_1)):
self.assertSequenceEqual(test_path_1[i],correct_path_1[i])
def test_corner_path(self):
'''
test nodes that forms a path with turns are correctly dealt with
'''
correct_path_1 = [(1, 2), (1, 1), (2, 1)]
test_path_1 = trace_missing_path((1, 2), (2, 1))
print(test_path_1)
self.assertEqual(len(test_path_1),len(correct_path_1))
for i in range(len(correct_path_1)):
self.assertSequenceEqual(test_path_1[i],correct_path_1[i])
def test_long_path(self):
'''
test a longer sequence of path
'''
correct_path_1 = [(16, 1), (17, 1), (18, 1), (
19, 1), (20, 1), (21, 1), (21, 2), (21, 3), (21, 4), (21, 5), (22, 5), (23, 5)]
test_path_1 = trace_missing_path((16, 1), (23, 5))
print(test_path_1)
self.assertEqual(len(test_path_1),len(correct_path_1))
for i in range(len(correct_path_1)):
self.assertSequenceEqual(test_path_1[i],correct_path_1[i])
if __name__ == '__main__':
unittest.main()