1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
use robot_simulator::*;
#[test]
fn robots_are_created_with_position_and_direction() {
let robot = Robot::new(0, 0, Direction::North);
assert_eq!((0, 0), robot.position());
assert_eq!(&Direction::North, robot.direction());
}
#[test]
fn positions_can_be_negative() {
let robot = Robot::new(-1, -1, Direction::South);
assert_eq!((-1, -1), robot.position());
assert_eq!(&Direction::South, robot.direction());
}
#[test]
fn turning_right_does_not_change_position() {
let robot = Robot::new(0, 0, Direction::North).turn_right();
assert_eq!((0, 0), robot.position());
}
#[test]
fn turning_right_from_north_points_the_robot_east() {
let robot = Robot::new(0, 0, Direction::North).turn_right();
assert_eq!(&Direction::East, robot.direction());
}
#[test]
fn turning_right_from_east_points_the_robot_south() {
let robot = Robot::new(0, 0, Direction::East).turn_right();
assert_eq!(&Direction::South, robot.direction());
}
#[test]
fn turning_right_from_south_points_the_robot_west() {
let robot = Robot::new(0, 0, Direction::South).turn_right();
assert_eq!(&Direction::West, robot.direction());
}
#[test]
fn turning_right_from_west_points_the_robot_north() {
let robot = Robot::new(0, 0, Direction::West).turn_right();
assert_eq!(&Direction::North, robot.direction());
}
#[test]
fn turning_left_does_not_change_position() {
let robot = Robot::new(0, 0, Direction::North).turn_left();
assert_eq!((0, 0), robot.position());
}
#[test]
fn turning_left_from_north_points_the_robot_west() {
let robot = Robot::new(0, 0, Direction::North).turn_left();
assert_eq!(&Direction::West, robot.direction());
}
#[test]
fn turning_left_from_west_points_the_robot_south() {
let robot = Robot::new(0, 0, Direction::West).turn_left();
assert_eq!(&Direction::South, robot.direction());
}
#[test]
fn turning_left_from_south_points_the_robot_east() {
let robot = Robot::new(0, 0, Direction::South).turn_left();
assert_eq!(&Direction::East, robot.direction());
}
#[test]
fn turning_left_from_east_points_the_robot_north() {
let robot = Robot::new(0, 0, Direction::East).turn_left();
assert_eq!(&Direction::North, robot.direction());
}
#[test]
fn advance_does_not_change_the_direction() {
let robot = Robot::new(0, 0, Direction::North).advance();
assert_eq!(&Direction::North, robot.direction());
}
#[test]
fn advance_increases_the_y_coordinate_by_one_when_facing_north() {
let robot = Robot::new(0, 0, Direction::North).advance();
assert_eq!((0, 1), robot.position());
}
#[test]
fn advance_decreases_the_y_coordinate_by_one_when_facing_south() {
let robot = Robot::new(0, 0, Direction::South).advance();
assert_eq!((0, -1), robot.position());
}
#[test]
fn advance_increases_the_x_coordinate_by_one_when_facing_east() {
let robot = Robot::new(0, 0, Direction::East).advance();
assert_eq!((1, 0), robot.position());
}
#[test]
fn advance_decreases_the_x_coordinate_by_one_when_facing_west() {
let robot = Robot::new(0, 0, Direction::West).advance();
assert_eq!((-1, 0), robot.position());
}
#[test]
fn follow_instructions_to_move_west_and_north() {
let robot = Robot::new(0, 0, Direction::North).instructions("LAAARALA");
assert_eq!((-4, 1), robot.position());
assert_eq!(&Direction::West, robot.direction());
}
#[test]
fn follow_instructions_to_move_west_and_south() {
let robot = Robot::new(2, -7, Direction::East).instructions("RRAAAAALA");
assert_eq!((-3, -8), robot.position());
assert_eq!(&Direction::South, robot.direction());
}
#[test]
fn follow_instructions_to_move_east_and_north() {
let robot = Robot::new(8, 4, Direction::South).instructions("LAAARRRALLLL");
assert_eq!((11, 5), robot.position());
assert_eq!(&Direction::North, robot.direction());
}
|