From 9d0dd5e6f78f609e3531b9fe80ccb0c72b326d24 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Mon, 26 Oct 2020 13:45:04 +0100 Subject: [PATCH] add tests for `is_valid()` method --- src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.rs b/src/main.rs index b483166..5229f42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -294,4 +294,27 @@ mod tests { w.create(); assert!(w.empty_position(Position { x: 0, y: 0 })); } + + #[test] + fn test_valid_position() { + let p: Position = Position { x: 1, y: 1 }; + let w: World = World { + x: 5, + y: 5, + map: Vec::new(), + }; + assert!(p.is_valid(w).is_ok()); + } + + #[test] + #[should_panic] + fn test_invalid_position() { + let p: Position = Position { x: -1, y: 1 }; + let w: World = World { + x: 5, + y: 5, + map: Vec::new(), + }; + assert!(p.is_valid(w).is_ok()); + } }