|
| 1 | +module main |
| 2 | + |
| 3 | +fn test_create_robot__at_origin_facing_north() { |
| 4 | + robot := Robot.new(0, 0, .north) |
| 5 | + assert robot.position.x == 0 |
| 6 | + assert robot.position.y == 0 |
| 7 | + assert robot.direction == .north |
| 8 | +} |
| 9 | + |
| 10 | +fn test_create_robot__at_negative_position_facing_south() { |
| 11 | + robot := Robot.new(-1, -1, .south) |
| 12 | + assert robot.position.x == -1 |
| 13 | + assert robot.position.y == -1 |
| 14 | + assert robot.direction == .south |
| 15 | +} |
| 16 | + |
| 17 | +fn test_rotating_clockwise__changes_north_to_east() { |
| 18 | + mut robot := Robot.new(0, 0, .north) |
| 19 | + robot.move('R') |
| 20 | + assert robot.position.x == 0 |
| 21 | + assert robot.position.y == 0 |
| 22 | + assert robot.direction == .east |
| 23 | +} |
| 24 | + |
| 25 | +fn test_rotating_clockwise__changes_east_to_south() { |
| 26 | + mut robot := Robot.new(0, 0, .east) |
| 27 | + robot.move('R') |
| 28 | + assert robot.position.x == 0 |
| 29 | + assert robot.position.y == 0 |
| 30 | + assert robot.direction == .south |
| 31 | +} |
| 32 | + |
| 33 | +fn test_rotating_clockwise__changes_south_to_west() { |
| 34 | + mut robot := Robot.new(0, 0, .south) |
| 35 | + robot.move('R') |
| 36 | + assert robot.position.x == 0 |
| 37 | + assert robot.position.y == 0 |
| 38 | + assert robot.direction == .west |
| 39 | +} |
| 40 | + |
| 41 | +fn test_rotating_clockwise__changes_west_to_north() { |
| 42 | + mut robot := Robot.new(0, 0, .west) |
| 43 | + robot.move('R') |
| 44 | + assert robot.position.x == 0 |
| 45 | + assert robot.position.y == 0 |
| 46 | + assert robot.direction == .north |
| 47 | +} |
| 48 | + |
| 49 | +fn test_rotating_counter_clockwise__changes_north_to_west() { |
| 50 | + mut robot := Robot.new(0, 0, .north) |
| 51 | + robot.move('L') |
| 52 | + assert robot.position.x == 0 |
| 53 | + assert robot.position.y == 0 |
| 54 | + assert robot.direction == .west |
| 55 | +} |
| 56 | + |
| 57 | +fn test_rotating_counter_clockwise__changes_west_to_south() { |
| 58 | + mut robot := Robot.new(0, 0, .west) |
| 59 | + robot.move('L') |
| 60 | + assert robot.position.x == 0 |
| 61 | + assert robot.position.y == 0 |
| 62 | + assert robot.direction == .south |
| 63 | +} |
| 64 | + |
| 65 | +fn test_rotating_counter_clockwise__changes_south_to_east() { |
| 66 | + mut robot := Robot.new(0, 0, .south) |
| 67 | + robot.move('L') |
| 68 | + assert robot.position.x == 0 |
| 69 | + assert robot.position.y == 0 |
| 70 | + assert robot.direction == .east |
| 71 | +} |
| 72 | + |
| 73 | +fn test_rotating_counter_clockwise__changes_east_to_north() { |
| 74 | + mut robot := Robot.new(0, 0, .east) |
| 75 | + robot.move('L') |
| 76 | + assert robot.position.x == 0 |
| 77 | + assert robot.position.y == 0 |
| 78 | + assert robot.direction == .north |
| 79 | +} |
| 80 | + |
| 81 | +fn test_moving_forward_one__facing_north_increments_y() { |
| 82 | + mut robot := Robot.new(0, 0, .north) |
| 83 | + robot.move('A') |
| 84 | + assert robot.position.x == 0 |
| 85 | + assert robot.position.y == 1 |
| 86 | + assert robot.direction == .north |
| 87 | +} |
| 88 | + |
| 89 | +fn test_moving_forward_one__facing_south_decrements_y() { |
| 90 | + mut robot := Robot.new(0, 0, .south) |
| 91 | + robot.move('A') |
| 92 | + assert robot.position.x == 0 |
| 93 | + assert robot.position.y == -1 |
| 94 | + assert robot.direction == .south |
| 95 | +} |
| 96 | + |
| 97 | +fn test_moving_forward_one__facing_east_increments_x() { |
| 98 | + mut robot := Robot.new(0, 0, .east) |
| 99 | + robot.move('A') |
| 100 | + assert robot.position.x == 1 |
| 101 | + assert robot.position.y == 0 |
| 102 | + assert robot.direction == .east |
| 103 | +} |
| 104 | + |
| 105 | +fn test_moving_forward_one__facing_west_decrements_x() { |
| 106 | + mut robot := Robot.new(0, 0, .west) |
| 107 | + robot.move('A') |
| 108 | + assert robot.position.x == -1 |
| 109 | + assert robot.position.y == 0 |
| 110 | + assert robot.direction == .west |
| 111 | +} |
| 112 | + |
| 113 | +fn test_follow_series_of_instructions__moving_east_and_north_from_readme() { |
| 114 | + mut robot := Robot.new(7, 3, .north) |
| 115 | + robot.move('RAALAL') |
| 116 | + assert robot.position.x == 9 |
| 117 | + assert robot.position.y == 4 |
| 118 | + assert robot.direction == .west |
| 119 | +} |
| 120 | + |
| 121 | +fn test_follow_series_of_instructions__moving_west_and_north() { |
| 122 | + mut robot := Robot.new(0, 0, .north) |
| 123 | + robot.move('LAAARALA') |
| 124 | + assert robot.position.x == -4 |
| 125 | + assert robot.position.y == 1 |
| 126 | + assert robot.direction == .west |
| 127 | +} |
| 128 | + |
| 129 | +fn test_follow_series_of_instructions__moving_west_and_south() { |
| 130 | + mut robot := Robot.new(2, -7, .east) |
| 131 | + robot.move('RRAAAAALA') |
| 132 | + assert robot.position.x == -3 |
| 133 | + assert robot.position.y == -8 |
| 134 | + assert robot.direction == .south |
| 135 | +} |
| 136 | + |
| 137 | +fn test_follow_series_of_instructions__moving_east_and_north() { |
| 138 | + mut robot := Robot.new(8, 4, .south) |
| 139 | + robot.move('LAAARRRALLLL') |
| 140 | + assert robot.position.x == 11 |
| 141 | + assert robot.position.y == 5 |
| 142 | + assert robot.direction == .north |
| 143 | +} |
0 commit comments