Skip to content

Commit 6b79609

Browse files
committed
WIP: Tests, stub file.
Tests come from exercism/problem-specifications#282 As discussed in exercism#117 we are providing a stub implementation so that ignored tests do not fail when a student hasn't yet implemented the functionality they exercise.
1 parent 6de3931 commit 6b79609

File tree

4 files changed

+204
-0
lines changed

4 files changed

+204
-0
lines changed

exercises/robot-simulator/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercises/robot-simulator/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[package]
2+
name = "robot-simulator"
3+
version = "0.0.0"

exercises/robot-simulator/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[derive(PartialEq, Debug)]
2+
pub enum Direction {
3+
North,
4+
East,
5+
South,
6+
West,
7+
}
8+
9+
pub struct Robot {
10+
}
11+
12+
impl Robot {
13+
pub fn new(x: isize, y: isize, d: &Direction) -> Self {
14+
Robot {}
15+
}
16+
17+
pub fn turn_right(&mut self) {}
18+
19+
pub fn turn_left(&mut self) {}
20+
21+
pub fn advance(&mut self) {}
22+
23+
pub fn instructions(&mut self, instructions: &str) {}
24+
25+
pub fn position(&self) -> (isize, isize) {
26+
(0, 0)
27+
}
28+
29+
pub fn direction(&self) -> Direction {
30+
Direction::North
31+
}
32+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
extern crate robot_simulator;
2+
3+
use robot_simulator::*;
4+
5+
#[test]
6+
fn robots_are_created_with_position_and_direction() {
7+
let robot = Robot::new(0, 0, &Direction::North);
8+
assert_eq!((0, 0), robot.position());
9+
assert_eq!(Direction::North, robot.direction());
10+
}
11+
12+
#[test]
13+
#[ignore]
14+
fn positions_can_be_negative() {
15+
let robot = Robot::new(-1, -1, &Direction::South);
16+
assert_eq!((-1, -1), robot.position());
17+
assert_eq!(Direction::South, robot.direction());
18+
}
19+
20+
#[test]
21+
#[ignore]
22+
fn turning_right_does_not_change_position() {
23+
let mut robot = Robot::new(0, 0, &Direction::North);
24+
robot.turn_right();
25+
assert_eq!((0, 0), robot.position());
26+
}
27+
28+
#[test]
29+
#[ignore]
30+
fn turning_right_from_north_points_the_robot_east() {
31+
let mut robot = Robot::new(0, 0, &Direction::North);
32+
robot.turn_right();
33+
assert_eq!(Direction::East, robot.direction());
34+
}
35+
36+
#[test]
37+
#[ignore]
38+
fn turning_right_from_east_points_the_robot_south() {
39+
let mut robot = Robot::new(0, 0, &Direction::East);
40+
robot.turn_right();
41+
assert_eq!(Direction::South, robot.direction());
42+
}
43+
44+
#[test]
45+
#[ignore]
46+
fn turning_right_from_south_points_the_robot_west() {
47+
let mut robot = Robot::new(0, 0, &Direction::South);
48+
robot.turn_right();
49+
assert_eq!(Direction::West, robot.direction());
50+
}
51+
52+
#[test]
53+
#[ignore]
54+
fn turning_right_from_west_points_the_robot_north() {
55+
let mut robot = Robot::new(0, 0, &Direction::West);
56+
robot.turn_right();
57+
assert_eq!(Direction::North, robot.direction());
58+
}
59+
60+
#[test]
61+
#[ignore]
62+
fn turning_left_does_not_change_position() {
63+
let mut robot = Robot::new(0, 0, &Direction::North);
64+
robot.turn_left();
65+
assert_eq!((0, 0), robot.position());
66+
}
67+
68+
#[test]
69+
#[ignore]
70+
fn turning_left_from_north_points_the_robot_west() {
71+
let mut robot = Robot::new(0, 0, &Direction::North);
72+
robot.turn_left();
73+
assert_eq!(Direction::East, robot.direction());
74+
}
75+
76+
#[test]
77+
#[ignore]
78+
fn turning_left_from_west_points_the_robot_south() {
79+
let mut robot = Robot::new(0, 0, &Direction::East);
80+
robot.turn_left();
81+
assert_eq!(Direction::South, robot.direction());
82+
}
83+
84+
#[test]
85+
#[ignore]
86+
fn turning_left_from_south_points_the_robot_east() {
87+
let mut robot = Robot::new(0, 0, &Direction::South);
88+
robot.turn_left();
89+
assert_eq!(Direction::East, robot.direction());
90+
}
91+
92+
#[test]
93+
#[ignore]
94+
fn turning_left_from_east_points_the_robot_north() {
95+
let mut robot = Robot::new(0, 0, &Direction::East);
96+
robot.turn_left();
97+
assert_eq!(Direction::North, robot.direction());
98+
}
99+
100+
#[test]
101+
#[ignore]
102+
fn advance_does_not_change_the_direction() {
103+
let mut robot = Robot::new(0, 0, &Direction::North);
104+
robot.advance();
105+
assert_eq!(Direction::North, robot.direction());
106+
}
107+
108+
#[test]
109+
#[ignore]
110+
fn advance_increases_the_y_coordinate_by_one_when_facing_north() {
111+
let mut robot = Robot::new(0, 0, &Direction::North);
112+
robot.advance();
113+
assert_eq!((0, 1), robot.position());
114+
}
115+
116+
#[test]
117+
#[ignore]
118+
fn advance_decreases_the_y_coordinate_by_one_when_facing_south() {
119+
let mut robot = Robot::new(0, 0, &Direction::South);
120+
robot.advance();
121+
assert_eq!((0, -1), robot.position());
122+
}
123+
124+
#[test]
125+
#[ignore]
126+
fn advance_increases_the_x_coordinate_by_one_when_facing_east() {
127+
let mut robot = Robot::new(0, 0, &Direction::East);
128+
robot.advance();
129+
assert_eq!((1, 0), robot.position());
130+
}
131+
132+
#[test]
133+
#[ignore]
134+
fn advance_decreases_the_x_coordinate_by_one_when_facing_west() {
135+
let mut robot = Robot::new(0, 0, &Direction::West);
136+
robot.advance();
137+
assert_eq!((-1, 0), robot.position());
138+
}
139+
140+
#[test]
141+
#[ignore]
142+
fn follow_instructions_to_move_west_and_north() {
143+
let mut robot = Robot::new(0, 0, &Direction::North);
144+
robot.instructions("LAAARALA");
145+
assert_eq!((-4, 1), robot.position());
146+
assert_eq!(Direction::West, robot.direction());
147+
}
148+
149+
#[test]
150+
#[ignore]
151+
fn follow_instructions_to_move_west_and_south() {
152+
let mut robot = Robot::new(0, 0, &Direction::East);
153+
robot.instructions("RRAAAAALA");
154+
assert_eq!((-3, -8), robot.position());
155+
assert_eq!(Direction::South, robot.direction());
156+
}
157+
158+
#[test]
159+
#[ignore]
160+
fn follow_instructions_to_move_east_and_north() {
161+
let mut robot = Robot::new(0, 0, &Direction::South);
162+
robot.instructions("LAAARRRALLLL");
163+
assert_eq!((11, 5), robot.position());
164+
assert_eq!(Direction::North, robot.direction());
165+
}

0 commit comments

Comments
 (0)