Merge branch 'test-world' into 'master'

test of World methods

See merge request mhart/DancingDroids!24
This commit is contained in:
Martin HART 2020-10-20 17:38:16 +02:00
commit 73674d26de
1 changed files with 40 additions and 0 deletions

View File

@ -181,4 +181,44 @@ mod tests {
assert!(open_file("two_robots.txt").is_ok()); assert!(open_file("two_robots.txt").is_ok());
assert!(open_file("test_unexisting_file.extension").is_err()); assert!(open_file("test_unexisting_file.extension").is_err());
} }
#[test]
fn test_create_map() {
let mut w: World = World {
x: 5,
y: 5,
map: Vec::new(),
};
w.create_map();
assert_eq!(w.map, vec!['.'; 25]);
}
#[test]
fn test_set_robot() {
let r = Robot {
id: 0,
o: Orientation::N,
p: Position { x: 0, y: 0 },
q: Queue::new(),
};
let mut w: World = World {
x: 2,
y: 2,
map: Vec::new(),
};
w.create_map();
w.set_robot(r);
assert_eq!(w.map, vec!['↑', '.', '.', '.']);
}
#[test]
fn test_empty_position() {
let mut w: World = World {
x: 2,
y: 2,
map: Vec::new(),
};
w.create_map();
assert!(w.empty_position(Position { x: 0, y: 0 }));
}
} }