From ab4072f30c4916bda3dad4a42fa8ecbe764246d7 Mon Sep 17 00:00:00 2001 From: Lucas Jeub Date: Tue, 22 Sep 2026 09:44:19 +0200 Subject: [PATCH] the proptest for HashableProp was using equality on Prop instead of HashableProp --- .../entities/properties/prop/prop_hashable.rs | 45 +++++++++++++++++++ raphtory-tests/tests/graph_tests/db_tests.rs | 10 ++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/raphtory-api/src/core/entities/properties/prop/prop_hashable.rs b/raphtory-api/src/core/entities/properties/prop/prop_hashable.rs index ef85d5361e..1c7fab8f9c 100644 --- a/raphtory-api/src/core/entities/properties/prop/prop_hashable.rs +++ b/raphtory-api/src/core/entities/properties/prop/prop_hashable.rs @@ -174,6 +174,51 @@ mod tests { assert!(set.contains(Prop::Decimal(1.into()).as_ref())); } + #[test] + fn test_zero() { + let members = [ + Prop::F64(0.0), + Prop::F32(0.0), + Prop::F64(-0.0), + Prop::F32(-0.0), + Prop::U8(0), + Prop::U16(0), + Prop::U32(0), + Prop::I32(0), + Prop::I64(0), + Prop::Decimal(0.into()), + ]; + + let set: HashSet = members.iter().cloned().map(HashableProp::from).collect(); + + assert_eq!(set.len(), 1); // all zeros should be the same + for v in members { + assert!(set.contains(v.as_ref())); // all zeros should be in the set + } + } + + #[test] + fn test_inf_and_nan() { + let members = [ + Prop::F64(f64::INFINITY), + Prop::F64(f64::NEG_INFINITY), + Prop::F32(f32::INFINITY), + Prop::F32(f32::NEG_INFINITY), + ]; + let set: HashSet = members.iter().cloned().map(HashableProp::from).collect(); + assert_eq!(set.len(), 2); // the float types should be equivalent + for v in members { + assert!(set.contains(v.as_ref())) + } + + let nans = [Prop::F64(f64::NAN), Prop::F32(f32::NAN)]; + let set: HashSet = nans.iter().cloned().map(HashableProp::from).collect(); + assert_eq!(set.len(), 2); // Nan are never equal + for n in nans { + assert!(!set.contains(n.as_ref())); // Nan is never in the set + } + } + #[test] fn test_prop_int_hashing() { let members = [ diff --git a/raphtory-tests/tests/graph_tests/db_tests.rs b/raphtory-tests/tests/graph_tests/db_tests.rs index 3c831e9f88..aa09c3731a 100644 --- a/raphtory-tests/tests/graph_tests/db_tests.rs +++ b/raphtory-tests/tests/graph_tests/db_tests.rs @@ -3907,14 +3907,14 @@ fn test_group_by() { #[test] fn hashing_proptest() { - proptest!(|(a in prop_type(3).prop_flat_map(|dt| prop(&dt)), b in prop_type(3).prop_flat_map(|dt| prop(&dt)))| { + proptest!(|(a in prop_type(3).prop_flat_map(|dt| prop(&dt).prop_map(HashableProp)), b in prop_type(3).prop_flat_map(|dt| prop(&dt).prop_map(HashableProp)))| { let mut set = HashSet::new(); - set.insert(HashableProp(a.clone())); - assert!(set.contains(a.as_ref())); + set.insert(a.clone()); + assert!(set.contains(&a)); if a == b { - assert!(set.contains(b.as_ref())); + assert!(set.contains(&b)); } else { - assert!(!set.contains(b.as_ref())); + assert!(!set.contains(&b)); } } ) }