From bdf91b7777ae1e34fe17be9cca5bd93deeb9745b Mon Sep 17 00:00:00 2001 From: Martin HART Date: Fri, 30 Oct 2020 16:34:25 +0100 Subject: [PATCH] GnaGnaGna volo want that... --- src/robot.rs | 26 ++++++++++++++++++++++++++ src/world.rs | 28 ---------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/robot.rs b/src/robot.rs index a06e218..7ab8c5a 100644 --- a/src/robot.rs +++ b/src/robot.rs @@ -56,6 +56,19 @@ pub struct Position { pub y: i32, } +/// Check if instructions list is valid. +pub fn is_instructions(v: &Vec) -> bool { + for c in v { + match c { + 'F' => continue, + 'R' => continue, + 'L' => continue, + _ => return false, + } + } + true +} + #[cfg(test)] mod tests { use super::*; @@ -95,4 +108,17 @@ mod tests { assert_eq!(r.p.x, 0); assert_eq!(r.p.y, 3); } + + #[test] + fn is_instructions_test() { + let v = vec!['F', 'R', 'L', 'F']; + assert!(is_instructions(&v)); + } + + #[test] + #[should_panic] + fn is_instructions_test_fail() { + let v = vec!['F', 'R', 'L', 'Z']; + assert!(is_instructions(&v)); + } } diff --git a/src/world.rs b/src/world.rs index 927a82a..357b82d 100644 --- a/src/world.rs +++ b/src/world.rs @@ -3,31 +3,3 @@ pub struct World { pub x: i32, pub y: i32, } - -pub fn is_instructions(v: &Vec) -> bool { - for c in v { - match c { - 'F' => continue, - 'R' => continue, - 'L' => continue, - _ => return false, - } - } - true -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn is_instructions_test() { - let v = vec!['F', 'R', 'L', 'F']; - assert!(is_instructions(&v)); - } - #[test] - #[should_panic] - fn is_instructions_test_fail() { - let v = vec!['F', 'R', 'L', 'Z']; - assert!(is_instructions(&v)); - } -}