mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-21 01:13:15 +00:00
Uses an array of bigint to store sufficient bits in bloom filter. Updates all arithmetic to explicitly cast to bigint where necessary. Makes the hashn function for bloomfilter a parameter. Adds an implementation of hashn generated using nim compiler. Adds tests.
30 lines
840 B
TypeScript
30 lines
840 B
TypeScript
import { expect } from "chai";
|
|
|
|
import {
|
|
getMOverNBitsForK,
|
|
KTooLargeError,
|
|
NoSuitableRatioError
|
|
} from "./probabilities.js";
|
|
|
|
describe("Probabilities", () => {
|
|
it("should not allow k > 12", () => {
|
|
expect(() => getMOverNBitsForK(13, 0.01)).to.throw(KTooLargeError);
|
|
});
|
|
|
|
it("should not allow unachievable error rate", () => {
|
|
expect(() => getMOverNBitsForK(2, 0.00001)).to.throw(NoSuitableRatioError);
|
|
});
|
|
|
|
it("should return the correct m/n for k = 2, targetError = 0.1", () => {
|
|
expect(getMOverNBitsForK(2, 0.1)).to.equal(6);
|
|
});
|
|
|
|
it("should return the correct m/n for k = 7, targetError = 0.01", () => {
|
|
expect(getMOverNBitsForK(7, 0.01)).to.equal(10);
|
|
});
|
|
|
|
it("should return the correct m/n for k = 7, targetError = 0.001", () => {
|
|
expect(getMOverNBitsForK(7, 0.001)).to.equal(16);
|
|
});
|
|
});
|