Merge pull request #1782 from danielsomerfield/main

Fix all_fruits_types_in_basket to fail if all fruit kinds are not  included
This commit is contained in:
Mo 2024-06-24 13:00:53 +02:00 committed by GitHub
commit 0cd96afe63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,7 @@
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Hash, PartialEq, Eq)] #[derive(Hash, PartialEq, Eq, Debug)]
enum Fruit { enum Fruit {
Apple, Apple,
Banana, Banana,
@ -81,9 +81,20 @@ mod tests {
#[test] #[test]
fn all_fruit_types_in_basket() { fn all_fruit_types_in_basket() {
let fruit_kinds = vec![
Fruit::Apple,
Fruit::Banana,
Fruit::Mango,
Fruit::Lychee,
Fruit::Pineapple,
];
let mut basket = get_fruit_basket(); let mut basket = get_fruit_basket();
fruit_basket(&mut 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); assert_ne!(amount, &0);
} }
} }