report mismatch counts

This commit is contained in:
Corwin 2023-09-05 23:02:49 +01:00
parent 5fc302dec9
commit 11fc38d840
No known key found for this signature in database

View file

@ -1066,15 +1066,22 @@ mod tests {
let number_of_levels = crate::level::Level::num_levels(); let number_of_levels = crate::level::Level::num_levels();
let mut failed_levels = Vec::new(); let mut failed_levels = Vec::new();
#[derive(Debug)]
#[allow(dead_code)]
struct MismatchCount {
given: i32,
used: i32,
}
#[derive(Debug)] #[derive(Debug)]
enum CompleteSimulationResult { enum CompleteSimulationResult {
Success, Success,
ExplicitLoss, ExplicitLoss,
InputSequenceOver, InputSequenceOver,
MismatchedItems(HashMap<crate::level::Item, ()>), MismatchedItems(HashMap<crate::level::Item, MismatchCount>),
} }
fn check_level_has_valid_items(level: usize) -> HashMap<crate::level::Item, ()> { fn check_level_has_valid_items(level: usize) -> HashMap<crate::level::Item, MismatchCount> {
let level = crate::level::Level::get_level(level); let level = crate::level::Level::get_level(level);
let mut given_items = HashMap::new(); let mut given_items = HashMap::new();
@ -1092,8 +1099,15 @@ mod tests {
let mut mismatched = HashMap::new(); let mut mismatched = HashMap::new();
for (&item, &count) in solution_items.iter() { for (&item, &count) in solution_items.iter() {
if *given_items.entry(item).or_insert(0) < count { let given_count = given_items.get(&item).copied().unwrap_or(0);
mismatched.insert(item, ()); if given_count < count {
mismatched.insert(
item,
MismatchCount {
given: given_count,
used: count,
},
);
} }
} }