Skip to content

Commit

Permalink
issue #68 seems to be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
folkvir committed May 16, 2024
1 parent dc36ceb commit 688e956
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/cuckoo-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,48 @@ test(`should not return an error when inserting and asking for ${max.toString()}
const currentrate = falsePositive / tries
expect(currentrate).toBeCloseTo(rate, rate)
})

test('issue#(https://github.com/Callidon/bloom-filters/issues/68)', () => {
const items = [
'https://www.youtube.com/watch?v=HJjxN05ewEc',
'https://www.youtube.com/watch?v=BZNUo7orS3k',
'https://www.youtube.com/watch?v=SD-McWZz_pk',
'https://www.youtube.com/watch?v=De4QjH9fpgo',
'https://www.youtube.com/watch?v=Hzko-cjHhTg',
'https://www.youtube.com/watch?v=vqR-8lgOmBE',
'https://www.youtube.com/watch?v=j6u0LH67YLk',
'https://www.youtube.com/watch?v=B2z8ikGLRh8',
'https://www.youtube.com/watch?v=N3ftBeP16TA',
'https://www.youtube.com/watch?v=38RBRPwODUk',
'https://www.youtube.com/watch?v=Ry8nSUfX6fY',
'https://www.youtube.com/watch?v=-KrYohUJvYw',
'https://www.youtube.com/watch?v=zRpl7Pr0fs4',
'https://www.youtube.com/watch?v=uYYiypp6WaY',
'https://www.youtube.com/watch?v=EPap21FBGbE',
'https://www.youtube.com/watch?v=zN2_0WC7UfU',
'https://www.youtube.com/watch?v=DNVwnkgTzbY',
]

const errorRate = 0.04 // 4 % error rate

const round = 100000
let c_false = 0

const filter = CuckooFilter.from(items, errorRate)
for (let i = 0; i < round; i++) {
let val = filter.has('https://www.youtube.com/watch?v=HJjxN05ewEc')
if (!val) {
c_false++
}

val = filter.has('https://www.youtube.com/watch?v=38RBRPwODUk')
if (!val) {
c_false++
}
val = filter.has('https://www.youtube.com/watch?v=-KrYohUJvYw')
if (!val) {
c_false++
}
}
expect(c_false).toEqual(0)
})

0 comments on commit 688e956

Please sign in to comment.