Skip to content

Commit 97b6725

Browse files
committed
check fp rate instead
1 parent 688e956 commit 97b6725

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tests/scalable-bloom-filter.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ test('should #has return false for an empty filter', () => {
1717
expect(filter.has('alice')).toBe(false)
1818
})
1919
test('should #has return correct values with added values', () => {
20-
const filter = ScalableBloomFilter.create(9, 0.0001)
20+
let fp = 0
21+
const filter = ScalableBloomFilter.create(9, 0.01)
2122
filter.seed = seed
2223
filter.add('alice')
2324
filter.add('bob')
2425
filter.add('carl')
25-
expect(filter.has('alice')).toBe(true)
26-
expect(filter.has('bob')).toBe(true)
27-
expect(filter.has('carl')).toBe(true)
28-
29-
// warning the filter is sufficiently big to trigger this at 100%
30-
expect(filter.has('somethingwhichdoesnotexist')).toBe(false)
26+
for (let i = 0; i < 10000; i++) {
27+
expect(filter.has('alice')).toBe(true)
28+
expect(filter.has('bob')).toBe(true)
29+
expect(filter.has('carl')).toBe(true)
30+
if (filter.has('somethingwhichdoesnotexist')) {
31+
fp++
32+
}
33+
}
34+
expect(fp / 10000).toBeLessThanOrEqual(0.01)
3135
})
3236

3337
test('should scale Partitioned Bloom Filter', () => {

0 commit comments

Comments
 (0)