|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Test;
|
|
|
3
|
+
|
|
|
4
|
+import static org.junit.Assert.assertTrue;
|
|
|
5
|
+
|
|
|
6
|
+public final class RobotTest {
|
|
|
7
|
+
|
|
|
8
|
+ @Test
|
|
|
9
|
+ public void testRobotIsCreatedWithCorrectInitialPosition() {
|
|
|
10
|
+ final GridPosition initialGridPosition = new GridPosition(0, 0);
|
|
|
11
|
+ final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
|
|
|
12
|
+
|
|
|
13
|
+ assertTrue(robot.getGridPosition().equals(initialGridPosition));
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ @Ignore
|
|
|
17
|
+ @Test
|
|
|
18
|
+ public void testRobotIsCreatedWithCorrectInitialOrientation() {
|
|
|
19
|
+ final Orientation initialOrientation = Orientation.NORTH;
|
|
|
20
|
+ final Robot robot = new Robot(new GridPosition(0, 0), initialOrientation);
|
|
|
21
|
+
|
|
|
22
|
+ assertTrue(robot.getOrientation().equals(initialOrientation));
|
|
|
23
|
+ }
|
|
|
24
|
+
|
|
|
25
|
+ @Ignore
|
|
|
26
|
+ @Test
|
|
|
27
|
+ public void testTurningRightDoesNotChangePosition() {
|
|
|
28
|
+ final GridPosition initialGridPosition = new GridPosition(0, 0);
|
|
|
29
|
+ final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
|
|
|
30
|
+
|
|
|
31
|
+ robot.turnRight();
|
|
|
32
|
+
|
|
|
33
|
+ assertTrue(robot.getGridPosition().equals(initialGridPosition));
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ @Ignore
|
|
|
37
|
+ @Test
|
|
|
38
|
+ public void testTurningRightCorrectlyChangesOrientationFromNorthToEast() {
|
|
|
39
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
|
|
|
40
|
+
|
|
|
41
|
+ robot.turnRight();
|
|
|
42
|
+
|
|
|
43
|
+ final Orientation expectedOrientation = Orientation.EAST;
|
|
|
44
|
+
|
|
|
45
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
46
|
+ }
|
|
|
47
|
+
|
|
|
48
|
+ @Ignore
|
|
|
49
|
+ @Test
|
|
|
50
|
+ public void testTurningRightCorrectlyChangesOrientationFromEastToSouth() {
|
|
|
51
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
|
|
|
52
|
+
|
|
|
53
|
+ robot.turnRight();
|
|
|
54
|
+
|
|
|
55
|
+ final Orientation expectedOrientation = Orientation.SOUTH;
|
|
|
56
|
+
|
|
|
57
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ @Ignore
|
|
|
61
|
+ @Test
|
|
|
62
|
+ public void testTurningRightCorrectlyChangesOrientationFromSouthToWest() {
|
|
|
63
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
|
|
|
64
|
+
|
|
|
65
|
+ robot.turnRight();
|
|
|
66
|
+
|
|
|
67
|
+ final Orientation expectedOrientation = Orientation.WEST;
|
|
|
68
|
+
|
|
|
69
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ @Ignore
|
|
|
73
|
+ @Test
|
|
|
74
|
+ public void testTurningRightCorrectlyChangesOrientationFromWestToNorth() {
|
|
|
75
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
|
|
|
76
|
+
|
|
|
77
|
+ robot.turnRight();
|
|
|
78
|
+
|
|
|
79
|
+ final Orientation expectedOrientation = Orientation.NORTH;
|
|
|
80
|
+
|
|
|
81
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ @Ignore
|
|
|
85
|
+ @Test
|
|
|
86
|
+ public void testTurningLeftDoesNotChangePosition() {
|
|
|
87
|
+ final GridPosition initialGridPosition = new GridPosition(0, 0);
|
|
|
88
|
+ final Robot robot = new Robot(initialGridPosition, Orientation.NORTH);
|
|
|
89
|
+
|
|
|
90
|
+ robot.turnLeft();
|
|
|
91
|
+
|
|
|
92
|
+ assertTrue(robot.getGridPosition().equals(initialGridPosition));
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ @Ignore
|
|
|
96
|
+ @Test
|
|
|
97
|
+ public void testTurningLeftCorrectlyChangesOrientationFromNorthToWest() {
|
|
|
98
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
|
|
|
99
|
+
|
|
|
100
|
+ robot.turnLeft();
|
|
|
101
|
+
|
|
|
102
|
+ final Orientation expectedOrientation = Orientation.WEST;
|
|
|
103
|
+
|
|
|
104
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ @Ignore
|
|
|
108
|
+ @Test
|
|
|
109
|
+ public void testTurningLeftCorrectlyChangesOrientationFromWestToSouth() {
|
|
|
110
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
|
|
|
111
|
+
|
|
|
112
|
+ robot.turnLeft();
|
|
|
113
|
+
|
|
|
114
|
+ final Orientation expectedOrientation = Orientation.SOUTH;
|
|
|
115
|
+
|
|
|
116
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ @Ignore
|
|
|
120
|
+ @Test
|
|
|
121
|
+ public void testTurningLeftCorrectlyChangesOrientationFromSouthToEast() {
|
|
|
122
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
|
|
|
123
|
+
|
|
|
124
|
+ robot.turnLeft();
|
|
|
125
|
+
|
|
|
126
|
+ final Orientation expectedOrientation = Orientation.EAST;
|
|
|
127
|
+
|
|
|
128
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ @Ignore
|
|
|
132
|
+ @Test
|
|
|
133
|
+ public void testTurningLeftCorrectlyChangesOrientationFromEastToNorth() {
|
|
|
134
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
|
|
|
135
|
+
|
|
|
136
|
+ robot.turnLeft();
|
|
|
137
|
+
|
|
|
138
|
+ final Orientation expectedOrientation = Orientation.NORTH;
|
|
|
139
|
+
|
|
|
140
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ @Ignore
|
|
|
144
|
+ @Test
|
|
|
145
|
+ public void testAdvancingDoesNotChangeOrientation() {
|
|
|
146
|
+ final Orientation initialOrientation = Orientation.NORTH;
|
|
|
147
|
+ final Robot robot = new Robot(new GridPosition(0, 0), initialOrientation);
|
|
|
148
|
+
|
|
|
149
|
+ robot.advance();
|
|
|
150
|
+
|
|
|
151
|
+ assertTrue(robot.getOrientation().equals(initialOrientation));
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
|
154
|
+ @Ignore
|
|
|
155
|
+ @Test
|
|
|
156
|
+ public void testAdvancingWhenFacingNorthIncreasesYCoordinateByOne() {
|
|
|
157
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
|
|
|
158
|
+
|
|
|
159
|
+ robot.advance();
|
|
|
160
|
+
|
|
|
161
|
+ final GridPosition expectedGridPosition = new GridPosition(0, 1);
|
|
|
162
|
+
|
|
|
163
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
164
|
+ }
|
|
|
165
|
+
|
|
|
166
|
+ @Ignore
|
|
|
167
|
+ @Test
|
|
|
168
|
+ public void testAdvancingWhenFacingSouthDecreasesYCoordinateByOne() {
|
|
|
169
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.SOUTH);
|
|
|
170
|
+
|
|
|
171
|
+ robot.advance();
|
|
|
172
|
+
|
|
|
173
|
+ final GridPosition expectedGridPosition = new GridPosition(0, -1);
|
|
|
174
|
+
|
|
|
175
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
176
|
+ }
|
|
|
177
|
+
|
|
|
178
|
+ @Ignore
|
|
|
179
|
+ @Test
|
|
|
180
|
+ public void testAdvancingWhenFacingEastIncreasesXCoordinateByOne() {
|
|
|
181
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.EAST);
|
|
|
182
|
+
|
|
|
183
|
+ robot.advance();
|
|
|
184
|
+
|
|
|
185
|
+ final GridPosition expectedGridPosition = new GridPosition(1, 0);
|
|
|
186
|
+
|
|
|
187
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
188
|
+ }
|
|
|
189
|
+
|
|
|
190
|
+ @Ignore
|
|
|
191
|
+ @Test
|
|
|
192
|
+ public void testAdvancingWhenFacingWestDecreasesXCoordinateByOne() {
|
|
|
193
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.WEST);
|
|
|
194
|
+
|
|
|
195
|
+ robot.advance();
|
|
|
196
|
+
|
|
|
197
|
+ final GridPosition expectedGridPosition = new GridPosition(-1, 0);
|
|
|
198
|
+
|
|
|
199
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ @Ignore
|
|
|
203
|
+ @Test
|
|
|
204
|
+ public void testInstructionsToMoveWestAndNorth() {
|
|
|
205
|
+ final Robot robot = new Robot(new GridPosition(0, 0), Orientation.NORTH);
|
|
|
206
|
+
|
|
|
207
|
+ robot.simulate("LAAARALA");
|
|
|
208
|
+
|
|
|
209
|
+ final GridPosition expectedGridPosition = new GridPosition(-4, 1);
|
|
|
210
|
+ final Orientation expectedOrientation = Orientation.WEST;
|
|
|
211
|
+
|
|
|
212
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
213
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
214
|
+ }
|
|
|
215
|
+
|
|
|
216
|
+ @Ignore
|
|
|
217
|
+ @Test
|
|
|
218
|
+ public void testInstructionsToMoveWestAndSouth() {
|
|
|
219
|
+ final Robot robot = new Robot(new GridPosition(2, -7), Orientation.EAST);
|
|
|
220
|
+
|
|
|
221
|
+ robot.simulate("RRAAAAALA");
|
|
|
222
|
+
|
|
|
223
|
+ final GridPosition expectedGridPosition = new GridPosition(-3, -8);
|
|
|
224
|
+ final Orientation expectedOrientation = Orientation.SOUTH;
|
|
|
225
|
+
|
|
|
226
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
227
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
228
|
+ }
|
|
|
229
|
+
|
|
|
230
|
+ @Ignore
|
|
|
231
|
+ @Test
|
|
|
232
|
+ public void testInstructionsToMoveEastAndNorth() {
|
|
|
233
|
+ final Robot robot = new Robot(new GridPosition(8, 4), Orientation.SOUTH);
|
|
|
234
|
+
|
|
|
235
|
+ robot.simulate("LAAARRRALLLL");
|
|
|
236
|
+
|
|
|
237
|
+ final GridPosition expectedGridPosition = new GridPosition(11, 5);
|
|
|
238
|
+ final Orientation expectedOrientation = Orientation.NORTH;
|
|
|
239
|
+
|
|
|
240
|
+ assertTrue(robot.getGridPosition().equals(expectedGridPosition));
|
|
|
241
|
+ assertTrue(robot.getOrientation().equals(expectedOrientation));
|
|
|
242
|
+ }
|
|
|
243
|
+
|
|
|
244
|
+}
|