File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -84,3 +84,28 @@ impl From<FilterType> for u8 {
8484 }
8585 }
8686}
87+
88+ #[ cfg( test) ]
89+ mod tests {
90+ use super :: * ;
91+ use test_log:: test;
92+
93+ #[ test]
94+ fn bloom_estimated_size_bpk ( ) {
95+ let policy = BloomConstructionPolicy :: BitsPerKey ( 10.0 ) ;
96+ let n = 1_000_000 ;
97+ let estimated_size = policy. estimated_filter_size ( n) ;
98+ // For 1 million keys and 10 bits per key, the size should be around 1.25 MB
99+ assert_eq ! ( estimated_size, 1_250_000 ) ;
100+ }
101+
102+ #[ test]
103+ fn bloom_estimated_size_fpr ( ) {
104+ let policy = BloomConstructionPolicy :: FalsePositiveRate ( 0.01 ) ;
105+ let n = 1_000_000 ;
106+ let estimated_size = policy. estimated_filter_size ( n) ;
107+ // For 1 million keys and 1% false positive rate, the size should be around 1.2 MB
108+ assert ! ( ( estimated_size as f32 ) < 1_300_000.0 ) ;
109+ assert ! ( ( estimated_size as f32 ) > 1_100_000.0 ) ;
110+ }
111+ }
You can’t perform that action at this time.
0 commit comments