UNPKG

hypertune

Version:

[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt

30 lines (27 loc) 883 B
import { expect, test } from "vitest"; import LRUCache from "./LRUCache"; test("LRUCache", () => { const cache = new LRUCache<number>(20); // Add more items than is the capacity. for (let i = 0; i < 25; i += 1) { cache.set(i.toString(), i); } // Check that oldest items were removed from the cache. for (let i = 0; i < 5; i += 1) { expect(cache.get(i.toString())).toEqual(null); } // Check that newest items remained. for (let i = 24; i >= 5; i -= 1) { expect(cache.get(i.toString())).toEqual(i); } // Check that get counts towards usage. // 24 should be the least recently used number at this point. cache.set("25", 25); expect(cache.get("24")).toEqual(null); expect(cache.get("23")).toEqual(23); // Check that purge works cache.purge(); for (let i = 0; i <= 25; i += 1) { expect(cache.get(i.toString())).toEqual(null); } });