From 46d4f27e24bda956a71f219dc8f99c08bbf05796 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Fri, 30 Oct 2020 15:15:11 +0100 Subject: [PATCH] Add instruction validator --- src/world.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/world.rs b/src/world.rs index 357b82d..43afa6e 100644 --- a/src/world.rs +++ b/src/world.rs @@ -3,3 +3,31 @@ pub struct World { pub x: i32, pub y: i32, } + +pub fn is_instruction(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_instruction_test() { + let v = vec!['F', 'R', 'L', 'F']; + assert!(is_instruction(&v)); + } + #[test] + #[should_panic] + fn is_instruction_test_fail() { + let v = vec!['F', 'R', 'L', 'Z']; + assert!(is_instruction(&v)); + } +}