The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { LRUCache } from "./lruCache"; |
| 3 | |
| 4 | describe("LRUCache", () => { |
| 5 | it("promotes on get and evicts least recently used", () => { |
| 6 | const cache = new LRUCache<string>(2, 1_000); |
| 7 | cache.set("a", "A", 10); |
| 8 | cache.set("b", "B", 10); |
| 9 | expect(cache.get("a")).toBe("A"); |
| 10 | |
| 11 | cache.set("c", "C", 10); |
| 12 | expect(cache.get("a")).toBe("A"); |
| 13 | expect(cache.get("b")).toBeNull(); |
| 14 | expect(cache.get("c")).toBe("C"); |
| 15 | }); |
| 16 | |
| 17 | it("evicts by memory budget", () => { |
| 18 | const cache = new LRUCache<string>(10, 25); |
| 19 | cache.set("a", "A", 10); |
| 20 | cache.set("b", "B", 10); |
| 21 | cache.set("c", "C", 10); |
| 22 | |
| 23 | expect(cache.get("a")).toBeNull(); |
| 24 | expect(cache.get("b")).toBe("B"); |
| 25 | expect(cache.get("c")).toBe("C"); |
| 26 | }); |
| 27 | |
| 28 | it("preserves an existing entry when an oversized replacement is rejected", () => { |
| 29 | const cache = new LRUCache<string>(2, 25); |
| 30 | cache.set("a", "A", 10); |
| 31 | cache.set("a", "oversized", 30); |
| 32 | |
| 33 | expect(cache.get("a")).toBe("A"); |
| 34 | }); |
| 35 | }); |