From 3c06c95f396b6e911076bc3291d5855ed01b5caa Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Sun, 26 Apr 2026 20:18:30 -0700 Subject: cleanup and ready for launch --- tests/history.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tests/history.test.ts') diff --git a/tests/history.test.ts b/tests/history.test.ts index a08c014..581c0ef 100644 --- a/tests/history.test.ts +++ b/tests/history.test.ts @@ -16,11 +16,7 @@ type Entry = { timestamp: number; }; -function entry(id: string, timestamp: number, favorite = false): Entry { - return { favorite, id, timestamp }; -} - -/*** TESTS -------------------------------------------- ***/ +/*** PROGRAM ------------------------------------------ ***/ test("evict keeps everything when under cap", () => { const entries = [entry("a", 3), entry("b", 2), entry("c", 1)]; @@ -35,7 +31,9 @@ test("evict drops the oldest non-favorites above cap", () => { entry("d", 2), entry("e", 1) ]; + const kept = evict(entries, 3); + expect(kept.map((e) => e.id)).toEqual(["a", "b", "c"]); }); @@ -47,6 +45,7 @@ test("evict never drops favorites", () => { entry("c", 8), entry("d", 7) ]; + const kept = evict(entries, 3); expect(kept.some((e) => e.id === "fav-old")).toEqual(true); @@ -60,6 +59,7 @@ test("evict can exceed cap when favorites alone do so", () => { entry("fav-3", 3, true), entry("regular", 2) ]; + const kept = evict(entries, 2); expect(kept.length).toEqual(3); @@ -73,6 +73,14 @@ test("evict sorts by timestamp descending", () => { entry("b", 2), entry("d", 0) ]; + const kept = evict(entries, 3); + expect(kept.map((e) => e.id)).toEqual(["a", "b", "c"]); }); + +/*** HELPER ------------------------------------------- ***/ + +function entry(id: string, timestamp: number, favorite = false): Entry { + return { favorite, id, timestamp }; +} -- cgit v1.2.3