Skip to content

Commit ba132ca

Browse files
committed
Fix flakey bloomfilter test prop_calc_size_fpr_fpr
It was failing for very large FPR values. This test involves rounding to an integer number of bits (filter size). With a low number of bits (corresponding to high FPRs and small number of elements) the accuracy loss from rounding is significant. So we need looser tolerances in these cases.
1 parent c8adf77 commit ba132ca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bloomfilter/tests/bloomfilter-tests.hs

+11-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,17 @@ prop_calc_size_fpr_fpr proxy (FPR fpr) (NumEntries numEntries) =
156156
(fromIntegral (B.sizeHashes bsize))
157157
~~~ fpr
158158
where
159-
(~~~) = withinTolerance 1e-6
159+
(~~~) = withinTolerance tolerance
160+
-- At small filter sizes (corresponding to high FPRs), we get significant
161+
-- reductions in accuracy due to rounding the number of bits to an integer.
162+
-- So we use greater tolerances for bigger FPRs.
163+
-- Contrast with prop_calc_policy_fpr which does not do rounding to an
164+
-- integer number of bits (it uses Double for bits per key), and thus can
165+
-- use a very small tolerance.
166+
tolerance | fpr <= 0.01 = 1e-6
167+
| fpr <= 0.05 = 1e-5
168+
| fpr <= 0.5 = 1e-4
169+
| otherwise = 1e-3
160170

161171
-- | Compare @sizeForBits@ against @falsePositiveRate@ with some tolerance for deviations
162172
prop_calc_size_fpr_bits :: BloomFilter bloom => Proxy bloom

0 commit comments

Comments
 (0)