Change .create_map() to .create(), and turn* to set*
This commit is contained in:
parent
73674d26de
commit
bb58983b6c
18
src/main.rs
18
src/main.rs
@ -12,7 +12,7 @@ struct World {
|
|||||||
|
|
||||||
impl World {
|
impl World {
|
||||||
/// Create a new map full of dots.
|
/// Create a new map full of dots.
|
||||||
fn create_map(&mut self) {
|
fn create(&mut self) {
|
||||||
self.map = vec!['.'; (self.x * self.y) as usize];
|
self.map = vec!['.'; (self.x * self.y) as usize];
|
||||||
}
|
}
|
||||||
/// Set robot on the map.
|
/// Set robot on the map.
|
||||||
@ -74,19 +74,19 @@ impl Robot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Apply North orientation to the robot.
|
/// Apply North orientation to the robot.
|
||||||
fn turn_north(&mut self) {
|
fn set_north(&mut self) {
|
||||||
self.o = Orientation::N
|
self.o = Orientation::N
|
||||||
}
|
}
|
||||||
/// Apply South orientation to the robot.
|
/// Apply South orientation to the robot.
|
||||||
fn turn_south(&mut self) {
|
fn set_south(&mut self) {
|
||||||
self.o = Orientation::S
|
self.o = Orientation::S
|
||||||
}
|
}
|
||||||
/// Apply East orientation to the robot.
|
/// Apply East orientation to the robot.
|
||||||
fn turn_east(&mut self) {
|
fn set_east(&mut self) {
|
||||||
self.o = Orientation::E
|
self.o = Orientation::E
|
||||||
}
|
}
|
||||||
/// Apply West orientation to the robot.
|
/// Apply West orientation to the robot.
|
||||||
fn turn_west(&mut self) {
|
fn set_west(&mut self) {
|
||||||
self.o = Orientation::W
|
self.o = Orientation::W
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,13 +183,13 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_map() {
|
fn test_create() {
|
||||||
let mut w: World = World {
|
let mut w: World = World {
|
||||||
x: 5,
|
x: 5,
|
||||||
y: 5,
|
y: 5,
|
||||||
map: Vec::new(),
|
map: Vec::new(),
|
||||||
};
|
};
|
||||||
w.create_map();
|
w.create();
|
||||||
assert_eq!(w.map, vec!['.'; 25]);
|
assert_eq!(w.map, vec!['.'; 25]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ mod tests {
|
|||||||
y: 2,
|
y: 2,
|
||||||
map: Vec::new(),
|
map: Vec::new(),
|
||||||
};
|
};
|
||||||
w.create_map();
|
w.create();
|
||||||
w.set_robot(r);
|
w.set_robot(r);
|
||||||
assert_eq!(w.map, vec!['↑', '.', '.', '.']);
|
assert_eq!(w.map, vec!['↑', '.', '.', '.']);
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ mod tests {
|
|||||||
y: 2,
|
y: 2,
|
||||||
map: Vec::new(),
|
map: Vec::new(),
|
||||||
};
|
};
|
||||||
w.create_map();
|
w.create();
|
||||||
assert!(w.empty_position(Position { x: 0, y: 0 }));
|
assert!(w.empty_position(Position { x: 0, y: 0 }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user