diff options
| author | Federico Igne <git@federicoigne.com> | 2021-01-03 16:48:43 +0000 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2021-11-03 18:55:08 +0000 |
| commit | b296156206a9b1bc4473c163bff44e6f2bc95573 (patch) | |
| tree | 6cfb199d183b2ec102489d0e6ba436819020c929 /rust/robot-simulator/tests/robot-simulator.rs | |
| parent | e7e054e21fd530fa6873b7aedd1fc4d4cfe5eb29 (diff) | |
| download | exercism-b296156206a9b1bc4473c163bff44e6f2bc95573.tar.gz exercism-b296156206a9b1bc4473c163bff44e6f2bc95573.zip | |
[rust] Robot Simulator
Diffstat (limited to 'rust/robot-simulator/tests/robot-simulator.rs')
| -rw-r--r-- | rust/robot-simulator/tests/robot-simulator.rs | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/rust/robot-simulator/tests/robot-simulator.rs b/rust/robot-simulator/tests/robot-simulator.rs new file mode 100644 index 0000000..14235e9 --- /dev/null +++ b/rust/robot-simulator/tests/robot-simulator.rs | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | use robot_simulator::*; | ||
| 2 | |||
| 3 | #[test] | ||
| 4 | fn robots_are_created_with_position_and_direction() { | ||
| 5 | let robot = Robot::new(0, 0, Direction::North); | ||
| 6 | assert_eq!((0, 0), robot.position()); | ||
| 7 | assert_eq!(&Direction::North, robot.direction()); | ||
| 8 | } | ||
| 9 | |||
| 10 | #[test] | ||
| 11 | fn positions_can_be_negative() { | ||
| 12 | let robot = Robot::new(-1, -1, Direction::South); | ||
| 13 | assert_eq!((-1, -1), robot.position()); | ||
| 14 | assert_eq!(&Direction::South, robot.direction()); | ||
| 15 | } | ||
| 16 | |||
| 17 | #[test] | ||
| 18 | fn turning_right_does_not_change_position() { | ||
| 19 | let robot = Robot::new(0, 0, Direction::North).turn_right(); | ||
| 20 | assert_eq!((0, 0), robot.position()); | ||
| 21 | } | ||
| 22 | |||
| 23 | #[test] | ||
| 24 | fn turning_right_from_north_points_the_robot_east() { | ||
| 25 | let robot = Robot::new(0, 0, Direction::North).turn_right(); | ||
| 26 | assert_eq!(&Direction::East, robot.direction()); | ||
| 27 | } | ||
| 28 | |||
| 29 | #[test] | ||
| 30 | fn turning_right_from_east_points_the_robot_south() { | ||
| 31 | let robot = Robot::new(0, 0, Direction::East).turn_right(); | ||
| 32 | assert_eq!(&Direction::South, robot.direction()); | ||
| 33 | } | ||
| 34 | |||
| 35 | #[test] | ||
| 36 | fn turning_right_from_south_points_the_robot_west() { | ||
| 37 | let robot = Robot::new(0, 0, Direction::South).turn_right(); | ||
| 38 | assert_eq!(&Direction::West, robot.direction()); | ||
| 39 | } | ||
| 40 | |||
| 41 | #[test] | ||
| 42 | fn turning_right_from_west_points_the_robot_north() { | ||
| 43 | let robot = Robot::new(0, 0, Direction::West).turn_right(); | ||
| 44 | assert_eq!(&Direction::North, robot.direction()); | ||
| 45 | } | ||
| 46 | |||
| 47 | #[test] | ||
| 48 | fn turning_left_does_not_change_position() { | ||
| 49 | let robot = Robot::new(0, 0, Direction::North).turn_left(); | ||
| 50 | assert_eq!((0, 0), robot.position()); | ||
| 51 | } | ||
| 52 | |||
| 53 | #[test] | ||
| 54 | fn turning_left_from_north_points_the_robot_west() { | ||
| 55 | let robot = Robot::new(0, 0, Direction::North).turn_left(); | ||
| 56 | assert_eq!(&Direction::West, robot.direction()); | ||
| 57 | } | ||
| 58 | |||
| 59 | #[test] | ||
| 60 | fn turning_left_from_west_points_the_robot_south() { | ||
| 61 | let robot = Robot::new(0, 0, Direction::West).turn_left(); | ||
| 62 | assert_eq!(&Direction::South, robot.direction()); | ||
| 63 | } | ||
| 64 | |||
| 65 | #[test] | ||
| 66 | fn turning_left_from_south_points_the_robot_east() { | ||
| 67 | let robot = Robot::new(0, 0, Direction::South).turn_left(); | ||
| 68 | assert_eq!(&Direction::East, robot.direction()); | ||
| 69 | } | ||
| 70 | |||
| 71 | #[test] | ||
| 72 | fn turning_left_from_east_points_the_robot_north() { | ||
| 73 | let robot = Robot::new(0, 0, Direction::East).turn_left(); | ||
| 74 | assert_eq!(&Direction::North, robot.direction()); | ||
| 75 | } | ||
| 76 | |||
| 77 | #[test] | ||
| 78 | fn advance_does_not_change_the_direction() { | ||
| 79 | let robot = Robot::new(0, 0, Direction::North).advance(); | ||
| 80 | assert_eq!(&Direction::North, robot.direction()); | ||
| 81 | } | ||
| 82 | |||
| 83 | #[test] | ||
| 84 | fn advance_increases_the_y_coordinate_by_one_when_facing_north() { | ||
| 85 | let robot = Robot::new(0, 0, Direction::North).advance(); | ||
| 86 | assert_eq!((0, 1), robot.position()); | ||
| 87 | } | ||
| 88 | |||
| 89 | #[test] | ||
| 90 | fn advance_decreases_the_y_coordinate_by_one_when_facing_south() { | ||
| 91 | let robot = Robot::new(0, 0, Direction::South).advance(); | ||
| 92 | assert_eq!((0, -1), robot.position()); | ||
| 93 | } | ||
| 94 | |||
| 95 | #[test] | ||
| 96 | fn advance_increases_the_x_coordinate_by_one_when_facing_east() { | ||
| 97 | let robot = Robot::new(0, 0, Direction::East).advance(); | ||
| 98 | assert_eq!((1, 0), robot.position()); | ||
| 99 | } | ||
| 100 | |||
| 101 | #[test] | ||
| 102 | fn advance_decreases_the_x_coordinate_by_one_when_facing_west() { | ||
| 103 | let robot = Robot::new(0, 0, Direction::West).advance(); | ||
| 104 | assert_eq!((-1, 0), robot.position()); | ||
| 105 | } | ||
| 106 | |||
| 107 | #[test] | ||
| 108 | fn follow_instructions_to_move_west_and_north() { | ||
| 109 | let robot = Robot::new(0, 0, Direction::North).instructions("LAAARALA"); | ||
| 110 | assert_eq!((-4, 1), robot.position()); | ||
| 111 | assert_eq!(&Direction::West, robot.direction()); | ||
| 112 | } | ||
| 113 | |||
| 114 | #[test] | ||
| 115 | fn follow_instructions_to_move_west_and_south() { | ||
| 116 | let robot = Robot::new(2, -7, Direction::East).instructions("RRAAAAALA"); | ||
| 117 | assert_eq!((-3, -8), robot.position()); | ||
| 118 | assert_eq!(&Direction::South, robot.direction()); | ||
| 119 | } | ||
| 120 | |||
| 121 | #[test] | ||
| 122 | fn follow_instructions_to_move_east_and_north() { | ||
| 123 | let robot = Robot::new(8, 4, Direction::South).instructions("LAAARRRALLLL"); | ||
| 124 | assert_eq!((11, 5), robot.position()); | ||
| 125 | assert_eq!(&Direction::North, robot.direction()); | ||
| 126 | } | ||
