Change .create_map() to .create(), and turn* to set*

This commit is contained in:
Martin HART 2020-10-20 21:39:45 +02:00
parent 73674d26de
commit bb58983b6c
1 changed files with 9 additions and 9 deletions

View File

@ -12,7 +12,7 @@ struct World {
impl World {
/// 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];
}
/// Set robot on the map.
@ -74,19 +74,19 @@ impl Robot {
}
}
/// Apply North orientation to the robot.
fn turn_north(&mut self) {
fn set_north(&mut self) {
self.o = Orientation::N
}
/// Apply South orientation to the robot.
fn turn_south(&mut self) {
fn set_south(&mut self) {
self.o = Orientation::S
}
/// Apply East orientation to the robot.
fn turn_east(&mut self) {
fn set_east(&mut self) {
self.o = Orientation::E
}
/// Apply West orientation to the robot.
fn turn_west(&mut self) {
fn set_west(&mut self) {
self.o = Orientation::W
}
}
@ -183,13 +183,13 @@ mod tests {
}
#[test]
fn test_create_map() {
fn test_create() {
let mut w: World = World {
x: 5,
y: 5,
map: Vec::new(),
};
w.create_map();
w.create();
assert_eq!(w.map, vec!['.'; 25]);
}
@ -206,7 +206,7 @@ mod tests {
y: 2,
map: Vec::new(),
};
w.create_map();
w.create();
w.set_robot(r);
assert_eq!(w.map, vec!['↑', '.', '.', '.']);
}
@ -218,7 +218,7 @@ mod tests {
y: 2,
map: Vec::new(),
};
w.create_map();
w.create();
assert!(w.empty_position(Position { x: 0, y: 0 }));
}
}