test of World methods

This commit is contained in:
Volodymyr Patuta 2020-10-20 17:33:57 +02:00
parent 08557961a1
commit 2603fb5751
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 }));
}
} }