Skip to content

Commit

Permalink
chore(test): Test murmurHash with utf8-strings, uint8arrays, empty in…
Browse files Browse the repository at this point in the history
…put etc.
  • Loading branch information
Hexagon committed Sep 14, 2024
1 parent 5c10976 commit 4002f38
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,37 @@ describe("objectHash", () => {
});
});

it("murmurHash", () => {
expect(murmurHash("Hello World")).toMatchInlineSnapshot("427197390");
expect(murmurHash("a")).toMatchInlineSnapshot("1009084850");
expect(murmurHash("aa")).toMatchInlineSnapshot("923832745");
expect(murmurHash("aaa")).toMatchInlineSnapshot("3033554871");
expect(murmurHash("aaaa")).toMatchInlineSnapshot("2129582471");
expect(murmurHash("aaaaa")).toMatchInlineSnapshot("3922341931");
expect(murmurHash("aaaaaa")).toMatchInlineSnapshot("1736445713");
expect(murmurHash("aaaaaaa")).toMatchInlineSnapshot("1497565372");
expect(murmurHash("aaaaaaaa")).toMatchInlineSnapshot("3662943087");
expect(murmurHash("aaaaaaaaa")).toMatchInlineSnapshot("2724714153");
describe("murmurHash", () => {
it("Generates correct hash for 0 bytes without seed", () => {
expect(murmurHash("")).toMatchInlineSnapshot("0");
});
it("Generates correct hash for 0 bytes with seed", () => {
expect(murmurHash("", 1)).toMatchInlineSnapshot("1364076727"); // 0x514E28B7
});
it("Generates correct hash for 'Hello World'", () => {
expect(murmurHash("Hello World")).toMatchInlineSnapshot("427197390");
});
it("Generates the correct hash for varios string lengths", () => {
expect(murmurHash("a")).toMatchInlineSnapshot("1009084850");
expect(murmurHash("aa")).toMatchInlineSnapshot("923832745");
expect(murmurHash("aaa")).toMatchInlineSnapshot("3033554871");
expect(murmurHash("aaaa")).toMatchInlineSnapshot("2129582471");
expect(murmurHash("aaaaa")).toMatchInlineSnapshot("3922341931");
expect(murmurHash("aaaaaa")).toMatchInlineSnapshot("1736445713");
expect(murmurHash("aaaaaaa")).toMatchInlineSnapshot("1497565372");
expect(murmurHash("aaaaaaaa")).toMatchInlineSnapshot("3662943087");
expect(murmurHash("aaaaaaaaa")).toMatchInlineSnapshot("2724714153");
});
it("Works with Uint8Arrays", () => {
expect(
murmurHash(new Uint8Array([0x21, 0x43, 0x65, 0x87])),
).toMatchInlineSnapshot("4116402539"); // 0xF55B516B
});
it("Handles UTF-8 high characters correctly", () => {
expect(murmurHash("ππππππππ", 0x97_47_b2_8c)).toMatchInlineSnapshot(
"3581961153",
);
});
});

it("sha256", () => {
Expand Down

0 comments on commit 4002f38

Please sign in to comment.