-
Notifications
You must be signed in to change notification settings - Fork 46
/
test_reeds_shepp.py
102 lines (82 loc) · 2.8 KB
/
test_reeds_shepp.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import unittest
from reeds_shepp import PathElement, Steering, Gear, path_length, timeflip, reflect, get_optimal_path
class TestPathElement(unittest.TestCase):
def setUp(self) -> None:
self.element = PathElement.create(13, Steering.LEFT, Gear.FORWARD)
def test_repr(self):
self.assertEqual(
repr(self.element),
"{ Steering: LEFT Gear: FORWARD distance: 13 }"
)
def test_reverse_gear(self):
self.assertEqual(
self.element.reverse_gear().gear,
Gear.BACKWARD
)
def test_reverse_steering(self):
self.assertEqual(
self.element.reverse_steering().steering,
Steering.RIGHT
)
def test_with_negative_parameter(self):
element = PathElement.create(-1, Steering.LEFT, Gear.FORWARD)
self.assertEqual(
element,
PathElement.create(1, Steering.LEFT, Gear.BACKWARD)
)
class TestPathLength(unittest.TestCase):
def test_with_positive_path_elements(self):
path = [PathElement.create(1, Steering.LEFT, Gear.FORWARD) for _ in range(2)]
self.assertEqual(
path_length(path),
2
)
class TestTimeflip(unittest.TestCase):
def setUp(self) -> None:
self.path = [PathElement.create(1, Steering.LEFT, g) for g in (Gear.FORWARD, Gear.BACKWARD)]
self.timeflipped = timeflip(self.path)
def test_it_flips_forward_backward(self):
self.assertEqual(
self.timeflipped[0].gear,
Gear.BACKWARD
)
self.assertEqual(
self.timeflipped[1].gear,
Gear.FORWARD
)
def test_it_does_not_mutate_original_path(self):
self.assertEqual(
self.path[0].gear,
Gear.FORWARD,
)
class TestReflect(unittest.TestCase):
def setUp(self) -> None:
self.path = [PathElement.create(1, s, Gear.FORWARD) for s in (Steering.LEFT, Steering.STRAIGHT, Steering.RIGHT)]
self.reflected = reflect(self.path)
def test_it_reflects_steering(self):
self.assertEqual(
self.reflected[0].steering,
Steering.RIGHT
)
self.assertEqual(
self.reflected[1].steering,
Steering.STRAIGHT
)
self.assertEqual(
self.reflected[2].steering,
Steering.LEFT
)
def test_it_does_not_mutate_original_path(self):
self.assertEqual(
self.path[0].steering,
Steering.LEFT,
)
class TestGetOptimalPath(unittest.TestCase):
def test_smoke_test(self):
path = get_optimal_path((0, 0, 0), (1, 0, 0))
self.assertEqual(
path,
[PathElement.create(1.0, Steering.STRAIGHT, Gear.FORWARD)]
)
if __name__ == '__main__':
unittest.main()