mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
fix(cache/unstable): fix flaky fibonacci test (#5872)
* fix(cache/unstable): Fix flaky fibonacci test * Attempt 2
This commit is contained in:
parent
d279c0a49a
commit
8782bdb699
14
cache/memoize_test.ts
vendored
14
cache/memoize_test.ts
vendored
@ -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", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user