-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update/rename test files/imports (still many broken)
- Loading branch information
1 parent
8798d95
commit 1cb3c49
Showing
366 changed files
with
3,386 additions
and
3,664 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { expect, test } from "bun:test"; | ||
import { LRUCache } from "../src/index.js"; | ||
|
||
let c: LRUCache<string, number>; | ||
let evicts: any[]; | ||
|
||
const init = () => { | ||
evicts = []; | ||
c = new LRUCache( | ||
[ | ||
["a", 1], | ||
["b", 2], | ||
["c", 3], | ||
], | ||
{ | ||
maxlen: 4, | ||
release: (k, v) => evicts.push([k, v]), | ||
} | ||
); | ||
}; | ||
|
||
test("max length", () => { | ||
init(); | ||
expect(c.length).toBe(3); | ||
c.set("d", 4); | ||
expect(c.length).toBe(4); | ||
c.set("e", 5); | ||
expect(c.length).toBe(4); | ||
expect(evicts).toEqual([["a", 1]]); | ||
}); | ||
|
||
test("get", () => { | ||
init(); | ||
expect(c.get("a")).toBe(1); | ||
expect(c.get("b")).toBe(2); | ||
expect([...c.keys()]).toEqual(["c", "a", "b"]); | ||
c.set("d", 4); | ||
expect([...c.keys()]).toEqual(["c", "a", "b", "d"]); | ||
c.set("e", 5); | ||
expect([...c.keys()]).toEqual(["a", "b", "d", "e"]); | ||
expect([...c.values()]).toEqual([1, 2, 4, 5]); | ||
expect(evicts).toEqual([["c", 3]]); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { expect, test } from "bun:test"; | ||
import { MRUCache } from "../src/index.js"; | ||
|
||
let c: MRUCache<string, number>; | ||
let evicts: any[]; | ||
|
||
const init = () => { | ||
evicts = []; | ||
c = new MRUCache( | ||
[ | ||
["a", 1], | ||
["b", 2], | ||
["c", 3], | ||
], | ||
{ | ||
maxlen: 4, | ||
release: (k, v) => evicts.push([k, v]), | ||
} | ||
); | ||
}; | ||
|
||
test("max length", () => { | ||
init(); | ||
expect(c.length).toBe(3); | ||
c.set("d", 4); | ||
expect(c.length).toBe(4); | ||
c.set("e", 5); | ||
expect(c.length).toBe(4); | ||
expect(evicts).toEqual([["d", 4]]); | ||
}); | ||
|
||
test("get", () => { | ||
init(); | ||
expect(c.get("a")).toBe(1); | ||
expect(c.get("b")).toBe(2); | ||
expect([...c.keys()]).toEqual(["b", "a", "c"]); | ||
c.set("d", 4); | ||
expect([...c.keys()]).toEqual(["d", "b", "a", "c"]); | ||
c.set("e", 5); | ||
expect([...c.keys()]).toEqual(["e", "b", "a", "c"]); | ||
expect([...c.values()]).toEqual([5, 2, 1, 3]); | ||
expect(evicts).toEqual([["d", 4]]); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { delayed } from "@thi.ng/compose"; | ||
import { expect, test } from "bun:test"; | ||
import { TLRUCache } from "../src/index.js"; | ||
|
||
let c: TLRUCache<string, number>; | ||
let evicts: any[]; | ||
|
||
const init = () => { | ||
evicts = []; | ||
c = new TLRUCache( | ||
[ | ||
["a", 1], | ||
["b", 2], | ||
["c", 3], | ||
], | ||
{ | ||
maxlen: 4, | ||
ttl: 10, | ||
release: (k, v) => evicts.push([k, v]), | ||
} | ||
); | ||
}; | ||
|
||
test("max length", () => { | ||
init(); | ||
expect(c.length).toBe(3); | ||
c.set("d", 4); | ||
expect(c.length).toBe(4); | ||
c.set("e", 5); | ||
expect(c.length).toBe(4); | ||
expect(evicts).toEqual([["a", 1]]); | ||
}); | ||
|
||
test("get lru", () => { | ||
init(); | ||
expect(c.get("a")).toBe(1); | ||
expect(c.get("b")).toBe(2); | ||
expect([...c.keys()]).toEqual(["c", "a", "b"]); | ||
c.set("d", 4); | ||
expect([...c.keys()]).toEqual(["c", "a", "b", "d"]); | ||
c.set("e", 5); | ||
expect([...c.keys()]).toEqual(["a", "b", "d", "e"]); | ||
expect([...c.values()]).toEqual([1, 2, 4, 5]); | ||
expect(evicts).toEqual([["c", 3]]); | ||
}); | ||
|
||
test("get ttl", async () => { | ||
init(); | ||
expect(c.set("a", 10, 100)).toBe(10); | ||
await delayed(null, 20); | ||
expect(c.has("b")).toBeFalse(); | ||
expect(c.has("c")).toBeFalse(); | ||
expect(evicts).toEqual([ | ||
["b", 2], | ||
["c", 3], | ||
]); | ||
expect([...c.keys()]).toEqual(["a"]); | ||
}); | ||
|
||
test("getSet ttl", async () => { | ||
init(); | ||
await delayed(null, 20); | ||
const v = await c.getSet("a", () => Promise.resolve(10)); | ||
expect(v).toBe(10); | ||
expect(c.has("b")).toBeFalse(); | ||
expect(c.has("c")).toBeFalse(); | ||
expect([...evicts]).toEqual([ | ||
["a", 1], | ||
["b", 2], | ||
["c", 3], | ||
]); | ||
expect([...c.keys()]).toEqual(["a"]); | ||
expect([...c.values()]).toEqual([10]); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { expect, test } from "bun:test"; | ||
// import { } from "../src/index.js"; | ||
|
||
test("cellular", () => {}); |
Oops, something went wrong.