Skip to content

Commit 5220063

Browse files
Merge pull request #738 from IntersectMBO/wenkokke/fix-prop_calc_size_fpr_bits
fix(bloomfilter): fix tolerance for prop_calc_size_fpr_bits and prop_calc_size_fpr_fpr
2 parents 9cea689 + f1ee797 commit 5220063

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

bloomfilter/tests/bloomfilter-tests.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,29 @@ prop_calc_size_fpr_fpr proxy (FPR fpr) (NumEntries numEntries) =
164164
-- Contrast with prop_calc_policy_fpr which does not do rounding to an
165165
-- integer number of bits (it uses Double for bits per key), and thus can
166166
-- use a very small tolerance.
167-
tolerance | fpr <= 0.01 = 1e-6
168-
| fpr <= 0.05 = 1e-5
169-
| fpr <= 0.5 = 1e-4
167+
tolerance | fpr <= 1e-4 = 1e-7
168+
| fpr <= 1e-3 = 1e-6
169+
| fpr <= 1e-2 = 1e-5
170+
| fpr <= 1e-1 = 1e-4
170171
| otherwise = 1e-3
171172

172173
-- | Compare @sizeForBits@ against @falsePositiveRate@ with some tolerance for deviations
173174
prop_calc_size_fpr_bits :: BloomFilter bloom => Proxy bloom
174175
-> BitsPerEntry -> NumEntries -> Property
175-
prop_calc_size_fpr_bits proxy (BitsPerEntry c) (NumEntries numEntries) =
176-
let policy = policyForBits proxy c
176+
prop_calc_size_fpr_bits proxy (BitsPerEntry bpe) (NumEntries numEntries) =
177+
let policy = policyForBits proxy bpe
177178
bsize = sizeForPolicy proxy policy numEntries
178179
in falsePositiveRate (fromIntegral (B.sizeBits bsize))
179180
(fromIntegral numEntries)
180181
(fromIntegral (B.sizeHashes bsize))
181182
~~~ policyFPR proxy policy
182183
where
183-
(~~~) = withinTolerance 1e-6
184+
(~~~) = withinTolerance tolerance
185+
tolerance | bpe >= 18 = 1e-7
186+
| bpe >= 13 = 1e-6
187+
| bpe >= 8 = 1e-5
188+
| bpe >= 4 = 1e-4
189+
| otherwise = 1e-3
184190

185191
-- reference implementations used for sanity checks
186192

0 commit comments

Comments
 (0)