From b7788a4480db02d7fb326626bca531bbe178b89e Mon Sep 17 00:00:00 2001 From: a14m Date: Fri, 2 Apr 2021 00:29:06 +0200 Subject: Add the testing of width and height in opts --- CLI/rust/src/game_of_life/opts.rs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CLI/rust/src/game_of_life/opts.rs b/CLI/rust/src/game_of_life/opts.rs index a0ed34b..9f612c1 100644 --- a/CLI/rust/src/game_of_life/opts.rs +++ b/CLI/rust/src/game_of_life/opts.rs @@ -20,6 +20,32 @@ pub(crate) mod validators { } } + #[cfg(test)] + mod is_fitting_term_width { + use super::*; + + #[test] + fn positive_value() { + assert!(is_fitting_term_width("13").is_ok()); + } + + + #[test] + fn value_too_large() { + assert!(is_fitting_term_width("1337").is_err()); + } + + #[test] + fn negative_value() { + assert!(is_fitting_term_width("-13").is_err()); + } + + #[test] + fn string_value() { + assert!(is_fitting_term_width("not a number").is_err()); + } + } + /// Validator to check if height configuration can be used /// /// The maximum height allowed is the current terminal window height - 2 @@ -38,6 +64,32 @@ pub(crate) mod validators { } } + #[cfg(test)] + mod is_fitting_term_height { + use super::*; + + #[test] + fn positive_value() { + assert!(is_fitting_term_height("13").is_ok()); + } + + + #[test] + fn value_too_large() { + assert!(is_fitting_term_height("1337").is_err()); + } + + #[test] + fn negative_value() { + assert!(is_fitting_term_height("-13").is_err()); + } + + #[test] + fn string_value() { + assert!(is_fitting_term_height("not a number").is_err()); + } + } + /// Validator to check if delay value is positive pub(crate) fn is_positive(val: &str) -> Result<(), String> { match val.parse::() { -- cgit v1.2.3