Add quickcheck tests for agb_hashmap

This commit is contained in:
Gwilym Inzani 2024-09-25 13:44:47 +01:00
parent 7202fc0119
commit d17c14c7d3
2 changed files with 16 additions and 0 deletions

View file

@ -16,3 +16,4 @@ rustc-hash = { version = "1", default-features = false }
[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["small_rng"] }
lazy_static = "1.4"
quickcheck = "1"

View file

@ -1453,4 +1453,19 @@ mod test {
assert_eq!(format!("{empty:?}"), "{}");
}
}
#[cfg(not(miri))]
quickcheck::quickcheck! {
fn test_against_btree_map(entries: Vec<(u8, u32)>) -> bool {
let std_hashmap = alloc::collections::BTreeMap::from_iter(entries.clone());
let agb_hashmap = HashMap::from_iter(entries);
if std_hashmap.len() != agb_hashmap.len() {
return false;
}
std_hashmap.iter().all(|(key, value)| agb_hashmap.get(key) == Some(value)) &&
agb_hashmap.iter().all(|(key, value)| std_hashmap.get(key) == Some(value))
}
}
}