Skip to content

Commit f902966

Browse files
JuliaKBremercmccandless
authored andcommitted
robot-simulator: updated tests to v3.0.0 (exercism#1543)
Updated tests to v2.3.0 , added Exception tests for invalid directions/instructions as well as tests for each direction the robot can go Closes exercism#1525
1 parent e1f699a commit f902966

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

exercises/robot-simulator/robot_simulator_test.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from robot_simulator import Robot, NORTH, EAST, SOUTH, WEST
44

55

6-
# Tests adapted from `problem-specifications//canonical-data.json` @ v2.2.0
6+
# Tests adapted from `problem-specifications//canonical-data.json` @ v3.0.0
77

88
class RobotSimulatorTest(unittest.TestCase):
99
def test_init(self):
@@ -17,16 +17,36 @@ def test_setup(self):
1717
self.assertEqual(robot.bearing, SOUTH)
1818

1919
def test_turn_right(self):
20-
robot = Robot()
21-
for direction in [EAST, SOUTH, WEST, NORTH]:
20+
dirA = [EAST, SOUTH, WEST, NORTH]
21+
dirB = [SOUTH, WEST, NORTH, EAST]
22+
for x in range(len(dirA)):
23+
robot = Robot(dirA[x], 0, 0)
2224
robot.turn_right()
23-
self.assertEqual(robot.bearing, direction)
25+
self.assertEqual(robot.bearing, dirB[x])
26+
27+
def test_change_direction_right(self):
28+
A = [NORTH, EAST, SOUTH, WEST]
29+
B = [EAST, SOUTH, WEST, NORTH]
30+
for x in range(len(A)):
31+
robot = Robot(A[x], 0, 0)
32+
robot.simulate("R")
33+
self.assertEqual(robot.bearing, B[x])
34+
35+
def test_change_direction_left(self):
36+
A = [NORTH, WEST, SOUTH, EAST]
37+
B = [WEST, SOUTH, EAST, NORTH]
38+
for x in range(len(A)):
39+
robot = Robot(A[x], 0, 0)
40+
robot.simulate("L")
41+
self.assertEqual(robot.bearing, B[x])
2442

2543
def test_turn_left(self):
26-
robot = Robot()
27-
for direction in [WEST, SOUTH, EAST, NORTH]:
44+
dirA = [EAST, SOUTH, WEST, NORTH]
45+
dirB = [NORTH, EAST, SOUTH, WEST]
46+
for x in range(len(dirA)):
47+
robot = Robot(dirA[x], 0, 0)
2848
robot.turn_left()
29-
self.assertEqual(robot.bearing, direction)
49+
self.assertEqual(robot.bearing, dirB[x])
3050

3151
def test_advance_positive_north(self):
3252
robot = Robot(NORTH, 0, 0)

0 commit comments

Comments
 (0)