From 506a71f678de00d537638aed4492c28a6689db5d Mon Sep 17 00:00:00 2001 From: EliasCubz Date: Thu, 29 Oct 2020 10:47:49 +0100 Subject: [PATCH] added test of function check collisions --- src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 90adc6d..c9abe05 100644 --- a/src/main.rs +++ b/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) -> Result { 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()); + } }