added test of function check collisions
This commit is contained in:
parent
782fccf31c
commit
506a71f678
20
src/main.rs
20
src/main.rs
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user