From 1ee584801a4b21d201aa0f7fd9b6a1ff54e9ab7c Mon Sep 17 00:00:00 2001 From: mhart Date: Tue, 13 Oct 2020 12:07:47 +0200 Subject: [PATCH 1/3] Add test to parse_orientation() parse_instruction() --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6d12ddd..11282a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,3 +41,25 @@ 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()); + } +} From 8c04fe7b9d7f13d5b7bd6481a4f7c2475279a55d Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <90917-fiplox@users.noreply.framagit.org> Date: Tue, 13 Oct 2020 12:15:04 +0200 Subject: [PATCH 2/3] Added `test_open_file()` --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.rs b/src/main.rs index 11282a9..d4782fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,4 +62,12 @@ mod tests { 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()); + assert!(open_file("no_permission.txt").is_err()); + } + } From 972850310e3c2d17556cd8a8dea9f81ab141a92c Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <90917-fiplox@users.noreply.framagit.org> Date: Tue, 13 Oct 2020 12:27:41 +0200 Subject: [PATCH 3/3] No need to test file without permission. --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d4782fb..a27e2b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,6 @@ mod tests { fn test_open_file() { assert!(open_file("two_robots.txt").is_ok()); assert!(open_file("test_unexisting_file.extension").is_err()); - assert!(open_file("no_permission.txt").is_err()); } }