From d5c6cce35d5cde05139d93f5237b694dd8e384ca Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Sun, 18 Jul 2021 10:10:43 -0500 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Cargo.toml | 8 ++++++++ src/lib.rs | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f49caeb --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "open_or_senior" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d506fbb --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,17 @@ +#![allow(unused)] + +fn open_or_senior(data: Vec<(i32, i32)>) -> Vec { + data.iter() + .map(|(age, hc)| if hc > &7 && age > &54 { "Senior".into() } else { "Open".into() }) + .collect::>() +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn returns_expected() { + assert_eq!(open_or_senior(vec![(45, 12), (55,21), (19, -2), (104, 20)]), vec!["Open", "Senior", "Open", "Senior"]); + assert_eq!(open_or_senior(vec![(3, 12), (55,1), (91, -2), (54, 23)]), vec!["Open", "Open", "Open", "Open"]); + } +}