commit d5c6cce35d5cde05139d93f5237b694dd8e384ca Author: Jim Infield Date: Sun Jul 18 10:10:43 2021 -0500 initial commit 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"]); + } +}