-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
61 lines (45 loc) · 1.84 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
import unittest
from rover import Rover
from planet import Planet
class TestRover(unittest.TestCase):
def setUp(self) -> None:
planet = Planet(5, 5, obstacles=[(1, 1), (2, 2)])
self.rover = Rover(planet, 0, 0, 0)
def test_rotate_clockwise(self):
for expected_direction in ("S", "W", "N", "E"):
self.rover.rotate_clockwise()
self.assertEqual(self.rover.direction.s, expected_direction)
def test_rotate_anticlockwise(self):
for expected_direction in ("N", "W", "S", "E"):
self.rover.rotate_anticlockwise()
self.assertEqual(self.rover.direction.s, expected_direction)
def test_move_forward(self):
self.rover.move_forward()
self.assertEqual(self.rover.location, (1, 0))
self.rover.rotate_anticlockwise()
self.rover.move_forward()
self.assertEqual(self.rover.location, (1, 0))
self.rover.rotate_clockwise()
self.rover.move_forward()
self.assertEqual(self.rover.location, (2, 0))
self.rover.move_backward()
self.rover.move_backward()
self.assertEqual(self.rover.location, (0, 0))
def test_move_backward(self):
self.rover.move_backward()
self.rover.move_backward()
self.rover.move_backward()
self.assertEqual(self.rover.location, (2, 0))
self.rover.rotate_clockwise()
self.rover.move_backward()
self.assertEqual(self.rover.location, (2, 1))
self.rover.move_backward()
self.assertEqual(self.rover.location, (2, 1))
self.rover.rotate_anticlockwise()
self.rover.rotate_anticlockwise()
self.rover.move_backward()
self.rover.rotate_clockwise()
self.rover.move_backward()
self.rover.move_backward()
self.assertEqual(self.rover.location, (0, 0))
unittest.main()