diff --git a/scripts/dsa.js b/scripts/dsa.js index f491c9f..268d91b 100644 --- a/scripts/dsa.js +++ b/scripts/dsa.js @@ -50,7 +50,7 @@ module.exports = { properties: [{ name: "length", type: "number", - scope: "public", + scope: "private", }] }, MinHeap: { diff --git a/src/__tests__/LRU.ts b/src/__tests__/LRU.ts index 3af365b..0c14dfc 100644 --- a/src/__tests__/LRU.ts +++ b/src/__tests__/LRU.ts @@ -1,8 +1,30 @@ -import ArrayList from "@code/LRU"; +import LRU from "@code/LRU"; test("LRU", function () { - const lru = new LRU(10); + const lru = new LRU(3) as ILRU; - lru. + expect(lru.get("foo")).toEqual(undefined); + lru.update("foo", 69); + expect(lru.get("foo")).toEqual(69); + + lru.update("bar", 420); + expect(lru.get("bar")).toEqual(420); + expect(lru.get("foo")).toEqual(69); + + lru.update("baz", 1337); + expect(lru.get("baz")).toEqual(1337); + expect(lru.get("foo")).toEqual(69); + + lru.update("ball", 69420); + expect(lru.get("ball")).toEqual(69420); + expect(lru.get("foo")).toEqual(undefined); + expect(lru.get("bar")).toEqual(420); + lru.update("foo", 69); + expect(lru.get("bar")).toEqual(420); + expect(lru.get("foo")).toEqual(69); + + // shouldn't of been deleted, but since bar was get'd, bar was added to the + // front of the list, so baz became the end + expect(lru.get("baz")).toEqual(undefined); });