GnaGnaGna volo want that...

This commit is contained in:
Martin HART 2020-10-30 16:34:25 +01:00
parent 843a26fa90
commit bdf91b7777
2 changed files with 26 additions and 28 deletions

View File

@ -56,6 +56,19 @@ pub struct Position {
pub y: i32, pub y: i32,
} }
/// Check if instructions list is valid.
pub fn is_instructions(v: &Vec<char>) -> bool {
for c in v {
match c {
'F' => continue,
'R' => continue,
'L' => continue,
_ => return false,
}
}
true
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -95,4 +108,17 @@ mod tests {
assert_eq!(r.p.x, 0); assert_eq!(r.p.x, 0);
assert_eq!(r.p.y, 3); 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));
}
} }

View File

@ -3,31 +3,3 @@ pub struct World {
pub x: i32, pub x: i32,
pub y: i32, pub y: i32,
} }
pub fn is_instructions(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_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));
}
}