@@ -415,10 +415,7 @@ impl<C: GeoConfig<Diff>> Count<Diff> for GeoDiffCount<'_, C> {
415415#[ cfg( test) ]
416416mod tests {
417417 use itertools:: Itertools ;
418- use rand:: {
419- seq:: { IndexedRandom , IteratorRandom } ,
420- RngCore , SeedableRng ,
421- } ;
418+ use rand:: { seq:: IteratorRandom , RngCore , SeedableRng } ;
422419
423420 use crate :: {
424421 build_hasher:: UnstableDefaultBuildHasher ,
@@ -653,14 +650,17 @@ mod tests {
653650 assert_eq ! ( before, after) ;
654651 }
655652
656- #[ test]
657- fn test_serialization_round_trip ( ) {
653+ // This helper exists in order to easily test serializing types with different
654+ // bucket types in the MSB sparse bit field representation. See tests below.
655+ fn serialization_round_trip < C : GeoConfig < Diff > + Default > ( ) {
658656 let mut rnd = rand:: rngs:: StdRng :: from_os_rng ( ) ;
659657
660658 // Run 100 simulations of random values being put into
661- // a diff counter
659+ // a diff counter. "Serializing" to a vector to emulate
660+ // writing to a disk, and then deserializing and asserting
661+ // the filters are equal.
662662 for _ in 0 ..100 {
663- let mut before = GeoDiffCount7 :: default ( ) ;
663+ let mut before = GeoDiffCount :: < ' _ , C > :: default ( ) ;
664664
665665 // Select a random number of items to insert
666666 let items = ( 1 ..1000 ) . choose ( & mut rnd) . unwrap ( ) ;
@@ -670,12 +670,23 @@ mod tests {
670670 }
671671
672672 let mut writer = vec ! [ ] ;
673-
674673 before. write ( & mut writer) . unwrap ( ) ;
675674
676- let after = GeoDiffCount7 :: from_bytes ( before. config . clone ( ) , & writer) ;
675+ let after = GeoDiffCount :: < ' _ , C > :: from_bytes ( before. config . clone ( ) , & writer) ;
677676
678677 assert_eq ! ( before, after) ;
679678 }
680679 }
680+
681+ #[ test]
682+ fn test_serialization_round_trip_7 ( ) {
683+ // Uses a u16 for MSB buckets
684+ serialization_round_trip :: < GeoDiffConfig7 > ( ) ;
685+ }
686+
687+ #[ test]
688+ fn test_serialization_round_trip_13 ( ) {
689+ // Uses a u32 for MSB buckets
690+ serialization_round_trip :: < GeoDiffConfig7 > ( ) ;
691+ }
681692}
0 commit comments