summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora14m <[email protected]>2021-04-02 00:29:06 +0200
committera14m <[email protected]>2021-04-02 00:29:06 +0200
commitb7788a4480db02d7fb326626bca531bbe178b89e (patch)
tree26cdf86180505740f5c8be507275e6fb4a0b78a4
parent0d5ce2fa0624d46d7673506c76534dc840b755cc (diff)
Add the testing of width and height in opts
-rw-r--r--CLI/rust/src/game_of_life/opts.rs52
1 files changed, 52 insertions, 0 deletions
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::<i16>() {