Update ESLint configuration, package.json, and README; improve formatting and versioning consistency. Adjust TypeScript configuration to disallow importing extensions and refine test scripts for better readability.
This commit is contained in:
@@ -10,7 +10,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash string keys", () => {
|
||||
const hash1 = hashFn.hash("hello", capacity);
|
||||
const hash2 = hashFn.hash("world", capacity);
|
||||
|
||||
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash1).toBeLessThan(capacity);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -22,7 +22,7 @@ describe("DefaultHashFunction", () => {
|
||||
const hash2 = hashFn.hash(3.14, capacity);
|
||||
const hash3 = hashFn.hash(0, capacity);
|
||||
const hash4 = hashFn.hash(-10, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash1).toBeLessThan(capacity);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -33,7 +33,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash boolean keys", () => {
|
||||
const hashTrue = hashFn.hash(true, capacity);
|
||||
const hashFalse = hashFn.hash(false, capacity);
|
||||
|
||||
|
||||
expect(hashTrue).toBeGreaterThanOrEqual(0);
|
||||
expect(hashTrue).toBeLessThan(capacity);
|
||||
expect(hashFalse).toBeGreaterThanOrEqual(0);
|
||||
@@ -57,7 +57,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash simple objects", () => {
|
||||
const obj = { name: "Alice", age: 30 };
|
||||
const hash = hashFn.hash(obj, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash arrays", () => {
|
||||
const arr = [1, 2, 3, 4, 5];
|
||||
const hash = hashFn.hash(arr, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -76,12 +76,12 @@ describe("DefaultHashFunction", () => {
|
||||
name: "Bob",
|
||||
address: {
|
||||
city: "NYC",
|
||||
zip: "10001"
|
||||
}
|
||||
}
|
||||
zip: "10001",
|
||||
},
|
||||
},
|
||||
};
|
||||
const hash = hashFn.hash(nested, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -89,7 +89,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should handle circular references gracefully", () => {
|
||||
const circular: { name: string; self?: unknown } = { name: "test" };
|
||||
circular.self = circular; // Create circular reference
|
||||
|
||||
|
||||
// Should not throw, should fall back to Object.prototype.toString
|
||||
const hash = hashFn.hash(circular, capacity);
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
@@ -99,7 +99,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash Date objects", () => {
|
||||
const date = new Date("2024-01-01");
|
||||
const hash = hashFn.hash(date, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -107,7 +107,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash RegExp objects", () => {
|
||||
const regex = /test/g;
|
||||
const hash = hashFn.hash(regex, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -115,7 +115,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash Error objects", () => {
|
||||
const error = new Error("Test error");
|
||||
const hash = hashFn.hash(error, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -143,7 +143,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash symbols", () => {
|
||||
const sym = Symbol("test");
|
||||
const hash = hashFn.hash(sym, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -151,7 +151,7 @@ describe("DefaultHashFunction", () => {
|
||||
it("should hash bigint", () => {
|
||||
const bigInt = BigInt(12345678901234567890n);
|
||||
const hash = hashFn.hash(bigInt, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -162,14 +162,14 @@ describe("DefaultHashFunction", () => {
|
||||
const key = "test-key";
|
||||
const hash1 = hashFn.hash(key, capacity);
|
||||
const hash2 = hashFn.hash(key, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBe(hash2);
|
||||
});
|
||||
|
||||
it("should return different hashes for different keys (usually)", () => {
|
||||
const hash1 = hashFn.hash("key1", capacity);
|
||||
const hash2 = hashFn.hash("key2", capacity);
|
||||
|
||||
|
||||
// Note: They COULD collide, but unlikely
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -180,7 +180,7 @@ describe("DefaultHashFunction", () => {
|
||||
const hash8 = hashFn.hash(key, 8);
|
||||
const hash16 = hashFn.hash(key, 16);
|
||||
const hash32 = hashFn.hash(key, 32);
|
||||
|
||||
|
||||
expect(hash8).toBeLessThan(8);
|
||||
expect(hash16).toBeLessThan(16);
|
||||
expect(hash32).toBeLessThan(32);
|
||||
@@ -196,7 +196,7 @@ describe("NumericHashFunction", () => {
|
||||
it("should hash positive integers", () => {
|
||||
const hash1 = hashFn.hash(42, capacity);
|
||||
const hash2 = hashFn.hash(100, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash1).toBeLessThan(capacity);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -205,14 +205,14 @@ describe("NumericHashFunction", () => {
|
||||
|
||||
it("should hash negative integers", () => {
|
||||
const hash = hashFn.hash(-42, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
|
||||
it("should hash zero", () => {
|
||||
const hash = hashFn.hash(0, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -220,7 +220,7 @@ describe("NumericHashFunction", () => {
|
||||
it("should hash floating point numbers", () => {
|
||||
const hash1 = hashFn.hash(3.14159, capacity);
|
||||
const hash2 = hashFn.hash(2.71828, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash1).toBeLessThan(capacity);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -229,14 +229,14 @@ describe("NumericHashFunction", () => {
|
||||
|
||||
it("should hash very large numbers", () => {
|
||||
const hash = hashFn.hash(Number.MAX_SAFE_INTEGER, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
|
||||
it("should hash very small numbers", () => {
|
||||
const hash = hashFn.hash(Number.MIN_VALUE, capacity);
|
||||
|
||||
|
||||
expect(hash).toBeGreaterThanOrEqual(0);
|
||||
expect(hash).toBeLessThan(capacity);
|
||||
});
|
||||
@@ -245,21 +245,21 @@ describe("NumericHashFunction", () => {
|
||||
describe("special numeric values", () => {
|
||||
it("should handle Infinity", () => {
|
||||
const hash = hashFn.hash(Infinity, capacity);
|
||||
|
||||
|
||||
// Should return 0 for non-finite numbers
|
||||
expect(hash).toBe(0);
|
||||
});
|
||||
|
||||
it("should handle negative Infinity", () => {
|
||||
const hash = hashFn.hash(-Infinity, capacity);
|
||||
|
||||
|
||||
// Should return 0 for non-finite numbers
|
||||
expect(hash).toBe(0);
|
||||
});
|
||||
|
||||
it("should handle NaN", () => {
|
||||
const hash = hashFn.hash(NaN, capacity);
|
||||
|
||||
|
||||
// Should return 0 for non-finite numbers
|
||||
expect(hash).toBe(0);
|
||||
});
|
||||
@@ -270,7 +270,7 @@ describe("NumericHashFunction", () => {
|
||||
const num = 42;
|
||||
const hash1 = hashFn.hash(num, capacity);
|
||||
const hash2 = hashFn.hash(num, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBe(hash2);
|
||||
});
|
||||
|
||||
@@ -279,7 +279,7 @@ describe("NumericHashFunction", () => {
|
||||
const hash8 = hashFn.hash(num, 8);
|
||||
const hash16 = hashFn.hash(num, 16);
|
||||
const hash32 = hashFn.hash(num, 32);
|
||||
|
||||
|
||||
expect(hash8).toBeLessThan(8);
|
||||
expect(hash16).toBeLessThan(16);
|
||||
expect(hash32).toBeLessThan(32);
|
||||
@@ -287,12 +287,12 @@ describe("NumericHashFunction", () => {
|
||||
|
||||
it("should distribute numbers evenly", () => {
|
||||
const hashes = new Set<number>();
|
||||
|
||||
|
||||
// Hash 100 sequential numbers
|
||||
for (let i = 0; i < 100; i++) {
|
||||
hashes.add(hashFn.hash(i, capacity));
|
||||
}
|
||||
|
||||
|
||||
// Should have good distribution (not all in one bucket)
|
||||
expect(hashes.size).toBeGreaterThan(1);
|
||||
});
|
||||
@@ -303,7 +303,7 @@ describe("NumericHashFunction", () => {
|
||||
const hash1 = hashFn.hash(-1, capacity);
|
||||
const hash2 = hashFn.hash(-100, capacity);
|
||||
const hash3 = hashFn.hash(-3.14, capacity);
|
||||
|
||||
|
||||
expect(hash1).toBeGreaterThanOrEqual(0);
|
||||
expect(hash1).toBeLessThan(capacity);
|
||||
expect(hash2).toBeGreaterThanOrEqual(0);
|
||||
@@ -315,10 +315,9 @@ describe("NumericHashFunction", () => {
|
||||
it("should handle same absolute value differently for positive and negative", () => {
|
||||
const hashPos = hashFn.hash(42, capacity);
|
||||
const hashNeg = hashFn.hash(-42, capacity);
|
||||
|
||||
|
||||
// They should hash to the same bucket (due to Math.abs in implementation)
|
||||
expect(hashPos).toBe(hashNeg);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user