Add instruction validator

This commit is contained in:
Martin HART 2020-10-30 15:15:11 +01:00
parent 6fa55b6924
commit 46d4f27e24
1 changed files with 28 additions and 0 deletions

View File

@ -3,3 +3,31 @@ pub struct World {
pub x: i32, pub x: i32,
pub y: i32, pub y: i32,
} }
pub fn is_instruction(v: &Vec<char>) -> 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));
}
}