feat: LRU tests
This commit is contained in:
parent
8b4725a628
commit
a7a1de34f5
2 changed files with 26 additions and 4 deletions
|
|
@ -50,7 +50,7 @@ module.exports = {
|
|||
properties: [{
|
||||
name: "length",
|
||||
type: "number",
|
||||
scope: "public",
|
||||
scope: "private",
|
||||
}]
|
||||
},
|
||||
MinHeap: {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue