test: 新增测试代码文件

This commit is contained in:
claude-code-best
2026-04-02 14:44:56 +08:00
parent 9c3803d16b
commit 006ad97fbb
32 changed files with 1102 additions and 68 deletions

View File

@@ -20,7 +20,11 @@ describe("djb2Hash", () => {
test("returns 32-bit integer", () => {
const hash = djb2Hash("some long string to hash");
expect(hash).toBe(hash | 0); // bitwise OR with 0 preserves 32-bit int
expect(Number.isSafeInteger(hash)).toBe(true);
});
test("has known answer for 'hello'", () => {
expect(djb2Hash("hello")).toBe(99162322);
});
});
@@ -36,6 +40,14 @@ describe("hashContent", () => {
test("different strings produce different hashes", () => {
expect(hashContent("abc")).not.toBe(hashContent("def"));
});
test("returns numeric string for empty string", () => {
expect(hashContent("")).toMatch(/^\d+$/);
});
test("returns numeric string format", () => {
expect(hashContent("hello")).toMatch(/^\d+$/);
});
});
describe("hashPair", () => {
@@ -54,4 +66,11 @@ describe("hashPair", () => {
test("disambiguates different splits", () => {
expect(hashPair("ts", "code")).not.toBe(hashPair("tsc", "ode"));
});
test("handles empty strings", () => {
expect(hashPair("", "")).toMatch(/^\d+$/);
expect(hashPair("", "a")).toMatch(/^\d+$/);
expect(hashPair("a", "")).toMatch(/^\d+$/);
expect(hashPair("", "a")).not.toBe(hashPair("a", ""));
});
});