This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrobot_simulator_test.py
More file actions
141 lines (99 loc) · 4 KB
/
Copy pathrobot_simulator_test.py
File metadata and controls
141 lines (99 loc) · 4 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import unittest
from robot_simulator import Robot, NORTH, EAST, SOUTH, WEST
# Tests adapted from `problem-specifications//canonical-data.json`
class RobotSimulatorTest(unittest.TestCase):
# Test create robot
def test_at_origin_facing_north(self):
robot = Robot(NORTH, 0, 0)
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
def test_at_negative_position_facing_south(self):
robot = Robot(SOUTH, -1, -1)
self.assertEqual(robot.coordinates, (-1, -1))
self.assertEqual(robot.direction, SOUTH)
# Test rotating clockwise
def test_changes_north_to_east(self):
robot = Robot(NORTH, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, EAST)
def test_changes_east_to_south(self):
robot = Robot(EAST, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, SOUTH)
def test_changes_south_to_west(self):
robot = Robot(SOUTH, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, WEST)
def test_changes_west_to_north(self):
robot = Robot(WEST, 0, 0)
robot.move("R")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
# Test rotating counter-clockwise
def test_changes_north_to_west(self):
robot = Robot(NORTH, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, WEST)
def test_changes_west_to_south(self):
robot = Robot(WEST, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, SOUTH)
def test_changes_south_to_east(self):
robot = Robot(SOUTH, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, EAST)
def test_changes_east_to_north(self):
robot = Robot(EAST, 0, 0)
robot.move("L")
self.assertEqual(robot.coordinates, (0, 0))
self.assertEqual(robot.direction, NORTH)
# Test moving forward one
def test_facing_north_increments_y(self):
robot = Robot(NORTH, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (0, 1))
self.assertEqual(robot.direction, NORTH)
def test_facing_south_decrements_y(self):
robot = Robot(SOUTH, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (0, -1))
self.assertEqual(robot.direction, SOUTH)
def test_facing_east_increments_x(self):
robot = Robot(EAST, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (1, 0))
self.assertEqual(robot.direction, EAST)
def test_facing_west_decrements_x(self):
robot = Robot(WEST, 0, 0)
robot.move("A")
self.assertEqual(robot.coordinates, (-1, 0))
self.assertEqual(robot.direction, WEST)
# Test follow series of instructions
def test_moving_east_and_north_from_readme(self):
robot = Robot(NORTH, 7, 3)
robot.move("RAALAL")
self.assertEqual(robot.coordinates, (9, 4))
self.assertEqual(robot.direction, WEST)
def test_moving_west_and_north(self):
robot = Robot(NORTH, 0, 0)
robot.move("LAAARALA")
self.assertEqual(robot.coordinates, (-4, 1))
self.assertEqual(robot.direction, WEST)
def test_moving_west_and_south(self):
robot = Robot(EAST, 2, -7)
robot.move("RRAAAAALA")
self.assertEqual(robot.coordinates, (-3, -8))
self.assertEqual(robot.direction, SOUTH)
def test_moving_east_and_north(self):
robot = Robot(SOUTH, 8, 4)
robot.move("LAAARRRALLLL")
self.assertEqual(robot.coordinates, (11, 5))
self.assertEqual(robot.direction, NORTH)
if __name__ == "__main__":
unittest.main()