logos-messaging-js/packages/sds/src/probabilities.spec.ts
Arseniy Klempner be93e4b71f
feat(sds): migrate bloomfilter to bigint and import hashn function from nim
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.
2025-02-05 17:27:41 -08:00

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);
});
});