GnaGnaGna volo want that...
This commit is contained in:
parent
843a26fa90
commit
bdf91b7777
26
src/robot.rs
26
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<char>) -> 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));
|
||||
}
|
||||
}
|
||||
|
28
src/world.rs
28
src/world.rs
@ -3,31 +3,3 @@ pub struct World {
|
||||
pub x: 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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user