diff --git a/src/main.rs b/src/main.rs index 6d12ddd..a27e2b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,3 +41,32 @@ fn open_file(filename: &str) -> io::Result { fn main() { let conf = open_file("two_robots.txt"); } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_orientation() { + assert!(parse_orientation('N').is_ok()); + assert!(parse_orientation('E').is_ok()); + assert!(parse_orientation('S').is_ok()); + assert!(parse_orientation('W').is_ok()); + assert!(parse_orientation('Z').is_err()); + } + + #[test] + fn test_parse_instruction() { + assert!(parse_instruction('L').is_ok()); + assert!(parse_instruction('R').is_ok()); + assert!(parse_instruction('F').is_ok()); + assert!(parse_instruction('Z').is_err()); + } + + #[test] + fn test_open_file() { + assert!(open_file("two_robots.txt").is_ok()); + assert!(open_file("test_unexisting_file.extension").is_err()); + } + +}