diff --git a/Cargo.toml b/Cargo.toml index 1864fd7..eab2824 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,8 @@ rand = "0.8" chrono = "0.4" # For examples rustc_version = "0.4" serde_json = "1" +proptest = "1.4.0" +test-strategy = "0.3.1" [features] serde1 = ["serde"] diff --git a/src/inclusive_map.rs b/src/inclusive_map.rs index 31957e0..ce11212 100644 --- a/src/inclusive_map.rs +++ b/src/inclusive_map.rs @@ -840,7 +840,34 @@ where #[cfg(test)] mod tests { use super::*; - use alloc::{format, vec, vec::Vec}; + use alloc::{format, vec, vec::Vec, string::String}; + use test_strategy::proptest; + use alloc as std; + + #[proptest] + fn test_arbitrary_map_u8(ranges: Vec<(RangeInclusive, String)>) { + let ranges: Vec<_> = ranges + .into_iter() + .filter(|(range, _value)| range.start() != range.end()) + .collect(); + let set = ranges + .iter() + .fold(RangeInclusiveMap::new(), |mut set, (range, value)| { + set.insert(range.clone(), value.clone()); + set + }); + + for value in 0..u8::MAX { + assert_eq!( + set.get(&value), + ranges + .iter() + .rev() + .find(|(range, _value)| range.contains(&value)) + .map(|(_range, value)| value) + ); + } + } trait RangeInclusiveMapExt { fn to_vec(&self) -> Vec<(RangeInclusive, V)>; diff --git a/src/inclusive_set.rs b/src/inclusive_set.rs index 8b6ddfe..6046935 100644 --- a/src/inclusive_set.rs +++ b/src/inclusive_set.rs @@ -409,7 +409,30 @@ where #[cfg(test)] mod tests { use super::*; + use alloc as std; use alloc::{format, vec, vec::Vec}; + use test_strategy::proptest; + + #[proptest] + fn test_arbitrary_set_u8(ranges: Vec>) { + let ranges: Vec<_> = ranges + .into_iter() + .filter(|range| range.start() != range.end()) + .collect(); + let set = ranges + .iter() + .fold(RangeInclusiveSet::new(), |mut set, range| { + set.insert(range.clone()); + set + }); + + for value in 0..u8::MAX { + assert_eq!( + set.contains(&value), + ranges.iter().any(|range| range.contains(&value)) + ); + } + } trait RangeInclusiveSetExt { fn to_vec(&self) -> Vec>; diff --git a/src/map.rs b/src/map.rs index 991611c..23662de 100644 --- a/src/map.rs +++ b/src/map.rs @@ -732,7 +732,34 @@ where #[cfg(test)] mod tests { use super::*; - use alloc::{format, vec, vec::Vec}; + use alloc as std; + use alloc::{format, string::String, vec, vec::Vec}; + use test_strategy::proptest; + + #[proptest] + fn test_arbitrary_map_u8(ranges: Vec<(Range, String)>) { + let ranges: Vec<_> = ranges + .into_iter() + .filter(|(range, _value)| range.start != range.end) + .collect(); + let set = ranges + .iter() + .fold(RangeMap::new(), |mut set, (range, value)| { + set.insert(range.clone(), value.clone()); + set + }); + + for value in 0..u8::MAX { + assert_eq!( + set.get(&value), + ranges + .iter() + .rev() + .find(|(range, _value)| range.contains(&value)) + .map(|(_range, value)| value) + ); + } + } trait RangeMapExt { fn to_vec(&self) -> Vec<(Range, V)>; diff --git a/src/set.rs b/src/set.rs index ee2976f..8aa1849 100644 --- a/src/set.rs +++ b/src/set.rs @@ -345,7 +345,28 @@ where #[cfg(test)] mod tests { use super::*; + use alloc as std; use alloc::{format, vec, vec::Vec}; + use test_strategy::proptest; + + #[proptest] + fn test_arbitrary_set_u8(ranges: Vec>) { + let ranges: Vec<_> = ranges + .into_iter() + .filter(|range| range.start != range.end) + .collect(); + let set = ranges.iter().fold(RangeSet::new(), |mut set, range| { + set.insert(range.clone()); + set + }); + + for value in 0..u8::MAX { + assert_eq!( + set.contains(&value), + ranges.iter().any(|range| range.contains(&value)) + ); + } + } trait RangeSetExt { fn to_vec(&self) -> Vec>;