From 0857e0bd5d62d994458212f4dddb1611d7cd04a2 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Tue, 10 Aug 2021 17:53:20 -0500 Subject: [PATCH] prepared for cargo watch --- src/main.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 54ab73b..bc9abe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,42 @@ fn main() { let args = vec![ - "string1", - "string2", + "01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17", + "02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41", ]; println!(); for arg in args { - println!("{}",func(&arg)); + println!("{:?}\n{:?}\n", arg, stati(arg)); }; println!(); } -fn func(s: &str) -> String { +fn stati(s: &str) -> String { s.into() } + +#[cfg(test)] +mod tests { + use super::*; + + fn dotest(strg: &str, exp: &str) -> () { + println!(" str: {:?};", strg); + let ans = stati(strg); + println!(" actual:\n{:?};", ans); + println!("expect:\n{:?};", exp); + println!(" {};", ans == exp); + assert_eq!(ans, exp); + println!("{};", "-"); + } + + #[test] + fn basic_tests() { + dotest("01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17", + "Range: 01|01|18 Average: 01|38|05 Median: 01|32|34"); + dotest("02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41", + "Range: 00|31|17 Average: 02|26|18 Median: 02|22|00"); + } +}