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)); - } -}