From 11fc38d840711bcea737c2e0398e2721e9c12528 Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 5 Sep 2023 23:02:49 +0100 Subject: [PATCH] report mismatch counts --- .../src/game/simulation/entity.rs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs b/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs index b697dff2..c8248890 100644 --- a/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs +++ b/examples/the-dungeon-puzzlers-lament/src/game/simulation/entity.rs @@ -1066,15 +1066,22 @@ mod tests { let number_of_levels = crate::level::Level::num_levels(); let mut failed_levels = Vec::new(); + #[derive(Debug)] + #[allow(dead_code)] + struct MismatchCount { + given: i32, + used: i32, + } + #[derive(Debug)] enum CompleteSimulationResult { Success, ExplicitLoss, InputSequenceOver, - MismatchedItems(HashMap), + MismatchedItems(HashMap), } - fn check_level_has_valid_items(level: usize) -> HashMap { + fn check_level_has_valid_items(level: usize) -> HashMap { let level = crate::level::Level::get_level(level); let mut given_items = HashMap::new(); @@ -1092,8 +1099,15 @@ mod tests { let mut mismatched = HashMap::new(); for (&item, &count) in solution_items.iter() { - if *given_items.entry(item).or_insert(0) < count { - mismatched.insert(item, ()); + let given_count = given_items.get(&item).copied().unwrap_or(0); + if given_count < count { + mismatched.insert( + item, + MismatchCount { + given: given_count, + used: count, + }, + ); } }