added test of function check collisions

This commit is contained in:
EliasCubz 2020-10-29 10:47:49 +01:00
parent 782fccf31c
commit 506a71f678
1 changed files with 19 additions and 1 deletions

View File

@ -29,11 +29,12 @@ fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
Ok(())
}
}
/// Check if the robot collide with another one at the given position.
fn check_collisions(
r: &robot::Robot,
w: &world::World,
h: HashMap<&robot::Position, &u32>,
h: &HashMap<&robot::Position, &u32>,
) -> Result<(), String> {
match h.get(&r.p) {
Some(&x) => Err(format!(
@ -43,6 +44,7 @@ fn check_collisions(
None => Ok(()),
}
}
/// Parse the config file, generate the world and robot pool.
fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, &'static str> {
let mut lines = conf.lines();
@ -134,4 +136,20 @@ mod tests {
assert!(check_map(&r, &w).is_ok());
}
#[test]
#[should_panic]
fn test_check_collisions() {
let mut r = robot::Robot::new(
0,
robot::Orientation::N,
robot::Position { x: 2, y: 3 },
vec!['F'],
);
let w = world::World { x: 10, y: 10 };
let mut h: HashMap<&robot::Position, &u32> = HashMap::new();
h.insert(&robot::Position { x: 2, y: 3 }, &1);
assert!(check_collisions(&r, &w, &h).is_ok());
}
}