import { encode, decode } from "./base36.mjs"; const N = 100_000; console.time(`${N} test cases`); for (let i = 0; i < N; i++) { const bytes = new Uint8Array(16); let num = 0n; for (let j = 0; j < bytes.length; j++) { bytes[j] = Math.random() * 256; num = num * 256n + BigInt(bytes[j]); } const encoded = encode(bytes); if (encoded !== num.toString(36).padStart(25, "0")) { throw new Error("encode: disagreement with BigInt.prototype.toString(36)"); } const decoded = decode(encoded); if (decoded.length !== 17) { throw new Error("decode: wrong output size"); } if (decoded[0] !== 0) { throw new Error("decode: disagreement with original byte array"); } for (let j = 0; j < bytes.length; j++) { if (bytes[j] !== decoded[j + 1]) { throw new Error("decode: disagreement with original byte array"); } } } console.timeEnd(`${N} test cases`);