fix(cache/unstable): fix flaky fibonacci test (#5872)

* fix(cache/unstable): Fix flaky fibonacci test

* Attempt 2
This commit is contained in:
lionel-rowe 2024-08-30 12:03:58 +08:00 committed by GitHub
parent d279c0a49a
commit 8782bdb699
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

14
cache/memoize_test.ts vendored
View File

@ -63,14 +63,16 @@ Deno.test("memoize() allows simple memoization with primitive arg", () => {
});
Deno.test("memoize() is performant for expensive fibonacci function", () => {
const fib = memoize((n: bigint): bigint =>
n <= 2n ? 1n : fib(n - 1n) + fib(n - 2n)
);
// Typically should take a maximum of a couple of milliseconds, but this
// test is really just a smoke test to make sure the memoization is working
// correctly, so we don't set a deadline to make sure it isn't flaky
// dependent on hardware, test runner, etc.
const fib = memoize((n: bigint): bigint => {
return n <= 2n ? 1n : fib(n - 1n) + fib(n - 2n);
});
const startTime = Date.now();
assertEquals(fib(100n), 354224848179261915075n);
assertAlmostEquals(Date.now(), startTime, 10);
});
Deno.test("memoize() allows multiple primitive args", () => {