From d17c14c7d35e4c33083751904a483d29bf7fb08a Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 25 Sep 2024 13:44:47 +0100 Subject: [PATCH] Add quickcheck tests for agb_hashmap --- agb-hashmap/Cargo.toml | 1 + agb-hashmap/src/lib.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/agb-hashmap/Cargo.toml b/agb-hashmap/Cargo.toml index 9e2637c5..dd82ffdc 100644 --- a/agb-hashmap/Cargo.toml +++ b/agb-hashmap/Cargo.toml @@ -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" diff --git a/agb-hashmap/src/lib.rs b/agb-hashmap/src/lib.rs index 898e712c..9eae6bd7 100644 --- a/agb-hashmap/src/lib.rs +++ b/agb-hashmap/src/lib.rs @@ -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)) + } + } }