Skip to content

Commit

Permalink
feat: LRU tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaulson committed Aug 10, 2022
1 parent 8b4725a commit a7a1de3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
properties: [{
name: "length",
type: "number",
scope: "public",
scope: "private",
}]
},
MinHeap: {
Expand Down
28 changes: 25 additions & 3 deletions src/__tests__/LRU.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import ArrayList from "@code/LRU";
import LRU from "@code/LRU";

test("LRU", function () {
const lru = new LRU<number>(10);
const lru = new LRU<string, number>(3) as ILRU<string, number>;

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);
});

0 comments on commit a7a1de3

Please sign in to comment.