Add instruction validator
This commit is contained in:
parent
6fa55b6924
commit
46d4f27e24
28
src/world.rs
28
src/world.rs
@ -3,3 +3,31 @@ pub struct World {
|
||||
pub x: 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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user