mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Fix all_fruits_types_in_basket to fail if all fruit kinds are not included
This commit is contained in:
parent
14e423fe53
commit
8bfe2ec71e
|
@ -18,7 +18,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,
|
||||||
|
@ -27,6 +27,14 @@ enum Fruit {
|
||||||
Pineapple,
|
Pineapple,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FRUIT_KINDS: [Fruit; 5] = [
|
||||||
|
Fruit::Apple,
|
||||||
|
Fruit::Banana,
|
||||||
|
Fruit::Mango,
|
||||||
|
Fruit::Lychee,
|
||||||
|
Fruit::Pineapple,
|
||||||
|
];
|
||||||
|
|
||||||
fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
||||||
let fruit_kinds = vec![
|
let fruit_kinds = vec![
|
||||||
Fruit::Apple,
|
Fruit::Apple,
|
||||||
|
@ -86,7 +94,10 @@ mod tests {
|
||||||
fn all_fruit_types_in_basket() {
|
fn all_fruit_types_in_basket() {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue