|
| 1 | +import unittest |
| 2 | +import robot_simulator |
| 3 | + |
| 4 | +suite "Robot_Simulator": |
| 5 | + test "Create robot -> at origin facing north": |
| 6 | + var robot = initRobot() |
| 7 | + check robot.direction == North |
| 8 | + |
| 9 | + test "Create robot -> at negative position facing south": |
| 10 | + var robot = initRobot(South,-1,-1) |
| 11 | + check robot.direction == South |
| 12 | + check robot.x_pos == -1 and robot.y_pos == -1 |
| 13 | + |
| 14 | + test "Rotating clockwise -> changes north to east": |
| 15 | + var robot = initRobot() |
| 16 | + robot.move("R") |
| 17 | + check robot.direction == East |
| 18 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 19 | + |
| 20 | + test "Rotating clockwise -> changes east to south": |
| 21 | + var robot = initRobot(East) |
| 22 | + robot.move("R") |
| 23 | + check robot.direction == South |
| 24 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 25 | + |
| 26 | + test "Rotating clockwise -> changes south to west": |
| 27 | + var robot = initRobot(South) |
| 28 | + robot.move("R") |
| 29 | + check robot.direction == West |
| 30 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 31 | + |
| 32 | + test "Rotating clockwise -> changes west to north": |
| 33 | + var robot = initRobot(West) |
| 34 | + robot.move("R") |
| 35 | + check robot.direction == North |
| 36 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 37 | + |
| 38 | + test "Rotating counter-clockwise -> changes north to west": |
| 39 | + var robot = initRobot() |
| 40 | + robot.move("L") |
| 41 | + check robot.direction == West |
| 42 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 43 | + |
| 44 | + test "Rotating counter-clockwise -> changes west to south": |
| 45 | + var robot = initRobot(West) |
| 46 | + robot.move("L") |
| 47 | + check robot.direction == South |
| 48 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 49 | + |
| 50 | + test "Rotating counter-clockwise -> changes south to east": |
| 51 | + var robot = initRobot(South) |
| 52 | + robot.move("L") |
| 53 | + check robot.direction == East |
| 54 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 55 | + |
| 56 | + test "Rotating counter-clockwise -> changes east to north": |
| 57 | + var robot = initRobot(East) |
| 58 | + robot.move("L") |
| 59 | + check robot.direction == North |
| 60 | + check robot.x_pos == 0 and robot.y_pos == 0 |
| 61 | + |
| 62 | + test "Moving forward one -> facing north increments Y": |
| 63 | + var robot = initRobot() |
| 64 | + robot.move("A") |
| 65 | + check robot.direction == North |
| 66 | + check robot.x_pos == 0 and robot.y_pos == 1 |
| 67 | + |
| 68 | + test "Moving forward one -> facing south decrements Y": |
| 69 | + var robot = initRobot(South) |
| 70 | + robot.move("A") |
| 71 | + check robot.direction == South |
| 72 | + check robot.x_pos == 0 and robot.y_pos == -1 |
| 73 | + |
| 74 | + test "Moving forward one -> facing east increments X": |
| 75 | + var robot = initRobot(East) |
| 76 | + robot.move("A") |
| 77 | + check robot.direction == East |
| 78 | + check robot.x_pos == 1 and robot.y_pos == 0 |
| 79 | + |
| 80 | + test "Moving forward one -> facing west decrements X": |
| 81 | + var robot = initRobot(West) |
| 82 | + robot.move("A") |
| 83 | + check robot.direction == West |
| 84 | + check robot.x_pos == -1 and robot.y_pos == 0 |
| 85 | + |
| 86 | + test "Follow series of instructions -> moving east and north from README": |
| 87 | + var robot = initRobot(North,7,3) |
| 88 | + robot.move("RAALAL") |
| 89 | + check robot.direction == West |
| 90 | + check robot.x_pos == 9 and robot.y_pos == 4 |
| 91 | + |
| 92 | + test "Follow series of instructions -> moving west and north": |
| 93 | + var robot = initRobot() |
| 94 | + robot.move("LAAARALA") |
| 95 | + check robot.direction == West |
| 96 | + check robot.x_pos == -4 and robot.y_pos == 1 |
| 97 | + |
| 98 | + test "Follow series of instructions -> moving west and south": |
| 99 | + var robot = initRobot(East,2,-7) |
| 100 | + robot.move("RRAAAAALA") |
| 101 | + check robot.direction == South |
| 102 | + check robot.x_pos == -3 and robot.y_pos == -8 |
| 103 | + |
| 104 | + test "Follow series of instructions -> moving east and north": |
| 105 | + var robot = initRobot(South,8,4) |
| 106 | + robot.move("LAAARRRALLLL") |
| 107 | + check robot.direction == North |
| 108 | + check robot.x_pos == 11 and robot.y_pos == 5 |
0 commit comments