diff options
| author | Daniel Somerfield <daniel.somerfield@hatchdata.com> | 2023-11-21 14:02:26 -0800 |
|---|---|---|
| committer | Daniel Somerfield <daniel.somerfield@hatchdata.com> | 2023-11-21 14:02:26 -0800 |
| commit | 8bfe2ec71e4800b798d7c0d7b3224ff2530a1c79 (patch) | |
| tree | b5c3156d9b023a6403024ef97fac1f7100666601 /exercises/11_hashmaps | |
| parent | 14e423fe532824fc4c92d4e198b74f1db048132e (diff) | |
Fix all_fruits_types_in_basket to fail if all fruit kinds are not included
Diffstat (limited to 'exercises/11_hashmaps')
| -rw-r--r-- | exercises/11_hashmaps/hashmaps2.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/exercises/11_hashmaps/hashmaps2.rs b/exercises/11_hashmaps/hashmaps2.rs index a592569..ab918cd 100644 --- a/exercises/11_hashmaps/hashmaps2.rs +++ b/exercises/11_hashmaps/hashmaps2.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; -#[derive(Hash, PartialEq, Eq)] +#[derive(Hash, PartialEq, Eq, Debug)] enum Fruit { Apple, Banana, @@ -27,6 +27,14 @@ enum Fruit { Pineapple, } +const FRUIT_KINDS: [Fruit; 5] = [ + Fruit::Apple, + Fruit::Banana, + Fruit::Mango, + Fruit::Lychee, + Fruit::Pineapple, +]; + fn fruit_basket(basket: &mut HashMap<Fruit, u32>) { let fruit_kinds = vec![ Fruit::Apple, @@ -81,12 +89,15 @@ mod tests { let count = basket.values().sum::<u32>(); assert!(count > 11); } - + #[test] fn all_fruit_types_in_basket() { let mut basket = get_fruit_basket(); fruit_basket(&mut basket); - for amount in basket.values() { + for fruit_kind in FRUIT_KINDS { + let amount = basket + .get(&fruit_kind) + .expect(format!("Fruit kind {:?} was not found in basket", fruit_kind).as_str()); assert_ne!(amount, &0); } } |
