diff options
| author | a14m <[email protected]> | 2021-04-08 00:26:19 +0200 |
|---|---|---|
| committer | a14m <[email protected]> | 2021-04-08 00:26:19 +0200 |
| commit | bc23a70a08810f03e5b9584f54bafc1c336759cd (patch) | |
| tree | 19971ca9c08b3239bc6ace8684132c67460d8f53 | |
| parent | 4c30d371e7b087f55bb84926228fac1da4c500f2 (diff) | |
Add banner implementation for the opts struct w/tests
| -rw-r--r-- | CLI/rust/src/game_of_life/opts.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/CLI/rust/src/game_of_life/opts.rs b/CLI/rust/src/game_of_life/opts.rs index 09e49c9..4a0d009 100644 --- a/CLI/rust/src/game_of_life/opts.rs +++ b/CLI/rust/src/game_of_life/opts.rs @@ -71,6 +71,14 @@ impl Opts { delay, }) } + + /// Print out the Banner info about used input or fallback to show the seed. + pub fn banner(&self) -> String { + match &self.input { + Some(i) => format!("Input: {}", &i), + None => format!("Seed: {}", &self.seed), + } + } } #[cfg(test)] @@ -173,3 +181,38 @@ mod from { assert_eq!(opts.delay, 13); } } + +#[cfg(test)] +mod banner { + use super::*; + + #[test] + fn with_input() { + let opts = Opts { + input: Some(String::from("./file")), + seed: 1337, + width: 4, + height: 3, + live_cell: 'L', + dead_cell: 'D', + delay: 13, + }; + + assert_eq!(opts.banner(), "Input: ./file"); + } + + #[test] + fn without_input() { + let opts = Opts { + input: None, + seed: 1337, + width: 4, + height: 3, + live_cell: 'L', + dead_cell: 'D', + delay: 13, + }; + + assert_eq!(opts.banner(), "Seed: 1337"); + } +} |
