use super::unsupported_items::{format_unsupported_breakdown, summarize};
use rustc_hash::FxHashMap;
fn map(pairs: &[(&str, u64)]) -> FxHashMap<String, u64> {
pairs.iter().map(|(k, v)| ((*k).to_string(), *v)).collect()
}
#[test]
fn the_breakdown_is_comma_space_separated_and_count_desc() {
let s = format_unsupported_breakdown(&map(&[
("IfcGeometricSet", 1),
("IfcAnnotationFillArea", 2),
("IfcPolyline", 7),
]));
assert_eq!(s, "IfcPolyline=7, IfcAnnotationFillArea=2, IfcGeometricSet=1");
}
#[test]
fn equal_counts_break_by_name_not_by_hash_order() {
let forward = map(&[("IfcZeta", 3), ("IfcAlpha", 3), ("IfcMu", 3)]);
let reverse = map(&[("IfcMu", 3), ("IfcAlpha", 3), ("IfcZeta", 3)]);
assert_eq!(
format_unsupported_breakdown(&forward),
"IfcAlpha=3, IfcMu=3, IfcZeta=3",
"ties must sort by name"
);
assert_eq!(
format_unsupported_breakdown(&forward),
format_unsupported_breakdown(&reverse),
"the same counts must print the same string whatever order they were inserted in"
);
}
#[test]
fn count_outranks_name() {
let s = format_unsupported_breakdown(&map(&[("IfcAlpha", 1), ("IfcZeta", 9)]));
assert_eq!(s, "IfcZeta=9, IfcAlpha=1");
}
#[test]
fn an_empty_map_formats_as_the_empty_string() {
assert_eq!(format_unsupported_breakdown(&FxHashMap::default()), "");
}
#[test]
fn summarize_totals_and_orders_the_same_way_the_string_does() {
let (total, by_type) = summarize(&map(&[("IfcZeta", 3), ("IfcAlpha", 3), ("IfcMu", 4)]));
assert_eq!(total, 10);
let order: Vec<&str> = by_type.iter().map(|rc| rc.reason.as_str()).collect();
assert_eq!(order, ["IfcMu", "IfcAlpha", "IfcZeta"]);
}