All checks were successful
🚀 Release / release (push) Successful in 4m7s
Reviewed-on: #31 Co-authored-by: Max Richter <max@max-richter.dev> Co-committed-by: Max Richter <max@max-richter.dev>
34 lines
904 B
TypeScript
34 lines
904 B
TypeScript
import { expect, test } from 'vitest';
|
|
import { fastHashArrayBuffer, fastHashString } from './fastHash';
|
|
|
|
test('fastHashString doesnt produce clashes', () => {
|
|
const hashA = fastHashString('abcdef');
|
|
const hashB = fastHashString('abcdeg');
|
|
const hashC = fastHashString('abcdeg');
|
|
|
|
expect(hashA).not.toEqual(hashB);
|
|
expect(hashB).toEqual(hashC);
|
|
});
|
|
|
|
test('fastHashArray doesnt product collisions', () => {
|
|
const a = new Int32Array(1000);
|
|
|
|
const hash_a = fastHashArrayBuffer(a);
|
|
a[0] = 1;
|
|
|
|
const hash_b = fastHashArrayBuffer(a);
|
|
|
|
expect(hash_a).not.toEqual(hash_b);
|
|
});
|
|
|
|
// test if the fastHashArray function is deterministic
|
|
test('fastHashArray is deterministic', () => {
|
|
const a = new Int32Array(1000);
|
|
a[42] = 69;
|
|
const b = new Int32Array(1000);
|
|
b[42] = 69;
|
|
const hashA = fastHashArrayBuffer(a);
|
|
const hashB = fastHashArrayBuffer(b);
|
|
expect(hashA).toEqual(hashB);
|
|
});
|