Files
sdk/js/tests/bloom.test.ts
menonsamir 7b655623c0 Fix Node example (#15)
* 0.1.7

* update examples (fix #14)

* Fix build

* Add crypto to bloom tests
2023-03-14 20:59:41 -07:00

26 lines
783 B
TypeScript

import { bloomLookup, bloomWrite, bloomInit } from '../data/bloom';
if (typeof crypto === 'undefined')
// eslint-disable-next-line @typescript-eslint/no-var-requires
(globalThis as any).crypto = (require('node:crypto') as any).webcrypto;
describe('bloom filter write + lookup', () => {
it.each([
[10, 24, ['a', 'b', 'c']],
[8, 18, ['x', 'y', 'z']]
])(`should work`, async (k, bits, vals) => {
const filter = bloomInit(k, bits);
for (const val of vals) {
bloomWrite(filter, val);
}
for (const val of vals) {
const got = await bloomLookup(filter, val);
expect(got).toEqual(true);
}
for (const val of vals) {
const got = await bloomLookup(filter, val + '############');
expect(got).toEqual(false);
}
});
});