-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_reeds_shepp.py
104 lines (84 loc) · 2.83 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
103
104
import unittest
import reeds_shepp as rs
class TestLetter(unittest.TestCase):
def setUp(self) -> None:
self.letter = rs.Letter(1.5, rs.Steering.LEFT, rs.Gear.FORWARD)
def test_repr(self):
self.assertEqual(
repr(self.letter),
'{ Steering: left' + '\tGear: forward' + '\tLength: 1.5 }'
)
def test_reverse_steering(self):
self.letter.reverse_steering()
self.assertEqual(
self.letter.steering,
rs.Steering.RIGHT
)
def test_reverse_gear(self):
self.letter.reverse_gear()
self.assertEqual(
self.letter.gear,
rs.Gear.BACKWARD
)
# def test_with_negative_parameter(self):
# letter = rs.Letter(-1.5, rs.Steering.LEFT, rs.Gear.FORWARD)
# self.assertEqual(
# letter,
# rs.Letter(1.5, rs.Steering.LEFT, rs.Gear.BACKWARD)
# )
class TestWordLength(unittest.TestCase):
def test_with_positive_path_elements(self):
word = [rs.Letter(1.5, rs.Steering.LEFT, rs.Gear.FORWARD) for _ in range(2)]
self.assertEqual(
rs.word_length(word),
3
)
class TestTimeflip(unittest.TestCase):
def setUp(self) -> None:
self.word = [rs.Letter(1.5, rs.Steering.LEFT, g) for g in (rs.Gear.FORWARD, rs.Gear.BACKWARD)]
self.timeflipped = rs.timeflip(self.word)
def test_it_flips_forward_backward(self):
self.assertEqual(
self.timeflipped[0].gear,
rs.Gear.BACKWARD
)
self.assertEqual(
self.timeflipped[1].gear,
rs.Gear.FORWARD
)
def test_it_does_not_mutate_original_word(self):
self.assertEqual(
self.word[0].gear,
rs.Gear.FORWARD,
)
class TestReflect(unittest.TestCase):
def setUp(self) -> None:
self.word = [rs.Letter(1.5, s, rs.Gear.FORWARD) for s in (rs.Steering.LEFT, rs.Steering.STRAIGHT, rs.Steering.RIGHT)]
self.reflected = rs.reflect(self.word)
def test_it_reflects_steering(self):
self.assertEqual(
self.reflected[0].steering,
rs.Steering.RIGHT
)
self.assertEqual(
self.reflected[1].steering,
rs.Steering.STRAIGHT
)
self.assertEqual(
self.reflected[2].steering,
rs.Steering.LEFT
)
def test_it_does_not_mutate_original_path(self):
self.assertEqual(
self.word[0].steering,
rs.Steering.LEFT,
)
class TestGetOptimalWord(unittest.TestCase):
def test_optimal_word(self):
word = rs.get_optimal_word((0, 0, 0), (1, 0, 0))
self.assertEqual(
repr(word),
repr([rs.Letter(1.0, rs.Steering.STRAIGHT, rs.Gear.FORWARD)])
)
if __name__ == '__main__':
unittest.main()