Skip to content

Commit

Permalink
test: update/rename test files/imports (still many broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 6, 2023
1 parent 8798d95 commit 1cb3c49
Show file tree
Hide file tree
Showing 366 changed files with 3,386 additions and 3,664 deletions.
43 changes: 43 additions & 0 deletions packages/cache/test/lru.test.ts
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]]);
});
48 changes: 0 additions & 48 deletions packages/cache/test/lru.ts

This file was deleted.

43 changes: 43 additions & 0 deletions packages/cache/test/mru.test.ts
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]]);
});
48 changes: 0 additions & 48 deletions packages/cache/test/mru.ts

This file was deleted.

74 changes: 74 additions & 0 deletions packages/cache/test/tlru.test.ts
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]);
});
86 changes: 0 additions & 86 deletions packages/cache/test/tlru.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/cellular/test/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/cellular/test/main.test.ts
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", () => {});
Loading

0 comments on commit 1cb3c49

Please sign in to comment.