Skip to content

Commit

Permalink
refactor: update all tests in _all_ pkgs
Browse files Browse the repository at this point in the history
- update all to use @thi.ng/testament
  • Loading branch information
postspectacular committed Sep 6, 2021
1 parent b6a4a18 commit 8b582bc
Show file tree
Hide file tree
Showing 242 changed files with 7,569 additions and 6,578 deletions.
6 changes: 3 additions & 3 deletions packages/adapt-dpi/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import * as assert from "assert";
// import { } from "../src";

describe("adapt-dpi", () => {
it("tests pending");
});
// group("adapt-dpi", () => {
// it("tests pending");
// });
21 changes: 9 additions & 12 deletions packages/adjacency/test/binary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from "assert";
import { group } from "@thi.ng/testament";
import { defAdjBitMatrix, Edge } from "../src";

const edges: Edge[] = [
Expand All @@ -8,28 +9,24 @@ const edges: Edge[] = [
[2, 0],
];

describe("adjacency (bitmatrix)", () => {
it("directed", () => {
group("adjacency (bitmatrix)", {
directed: () => {
const m = defAdjBitMatrix(4, [[1, 2]], false);
assert(m.hasEdge(1, 2));
assert.ok(m.hasEdge(1, 2));
assert.deepStrictEqual(m.neighbors(1), [2]);
assert.deepStrictEqual(m.neighbors(2), []);
assert.strictEqual(m.degree(1), 1);
assert.strictEqual(m.degree(2), 0);
assert.deepStrictEqual([...m.edges()], [[1, 2]]);
console.log(m.toString());
});
// console.log(m.toString());
},

it("undirected", () => {
undirected: () => {
const m = defAdjBitMatrix(6, edges, true);
assert.deepStrictEqual(
[...m.mat.data.slice(0, 6)],
[
1610612736,
2147483648,
2415919104,
536870912,
67108864,
1610612736, 2147483648, 2415919104, 536870912, 67108864,
134217728,
],
"data"
Expand All @@ -45,5 +42,5 @@ describe("adjacency (bitmatrix)", () => {
],
"edges"
);
});
},
});
15 changes: 8 additions & 7 deletions packages/adjacency/test/list.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as assert from "assert";
import { group } from "@thi.ng/testament";
import { defAdjList } from "../src";

describe("adjacency (list)", () => {
it("directed", () => {
group("adjacency (list)", {
directed: () => {
const m = defAdjList([
[1, 2],
[2, 0],
]);
assert(m.hasEdge(1, 2));
assert(m.hasEdge(2, 0));
assert(!m.hasEdge(2, 1));
assert(!m.hasEdge(0, 2));
assert.ok(m.hasEdge(1, 2));
assert.ok(m.hasEdge(2, 0));
assert.ok(!m.hasEdge(2, 1));
assert.ok(!m.hasEdge(0, 2));
assert.deepStrictEqual(m.neighbors(1), [2]);
assert.deepStrictEqual(m.neighbors(2), [0]);
assert.strictEqual(m.degree(1), 1);
Expand All @@ -22,5 +23,5 @@ describe("adjacency (list)", () => {
]
);
console.log(m.toString());
});
},
});
7 changes: 4 additions & 3 deletions packages/adjacency/test/mst.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { comparator2, distSq } from "@thi.ng/vectors";
import { group } from "@thi.ng/testament";
import * as assert from "assert";
import { mst } from "../src";

describe("unionfind", () => {
it("mst", () => {
group("unionfind", {
mst: () => {
const verts = [
[0, 0], // 0
[0, 1], // 1
Expand Down Expand Up @@ -49,5 +50,5 @@ describe("unionfind", () => {
[7, 8],
]
);
});
},
});
13 changes: 7 additions & 6 deletions packages/adjacency/test/sparse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Pair } from "@thi.ng/api";
import { group } from "@thi.ng/testament";
import * as assert from "assert";
import { defAdjMatrix } from "../src";

Expand All @@ -9,18 +10,18 @@ const edges: Pair<number, number>[] = [
[2, 0],
];

describe("adjacency (sparse)", () => {
it("edges directed", () => {
group("adjacency (sparse)", {
"edges directed": () => {
const m = defAdjMatrix(4, [], false);
m.addEdge(1, 2);
assert(m.hasEdge(1, 2));
assert.ok(m.hasEdge(1, 2));
assert.deepStrictEqual(m.neighbors(1), [2]);
assert.deepStrictEqual(m.neighbors(2), []);
assert.strictEqual(m.degree(1), 1);
assert.deepStrictEqual([...m.edges()], [[1, 2]]);
});
},

it("fromEdges, undirected", () => {
"fromEdges, undirected": () => {
const m = defAdjMatrix(6, edges, true);
assert.deepStrictEqual(m.rows, [0, 2, 3, 5, 6, 7, 8], "rows");
assert.deepStrictEqual(m.cols, [1, 2, 0, 0, 3, 2, 5, 4], "cols");
Expand All @@ -35,5 +36,5 @@ describe("adjacency (sparse)", () => {
],
"edges"
);
});
},
});
7 changes: 4 additions & 3 deletions packages/api/test/mixins.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as assert from "assert";
import { group } from "@thi.ng/testament";
import { Event, EVENT_ALL, INotify, INotifyMixin, Listener } from "../src";

describe("mixins", () => {
it("INotify", () => {
group("mixins", {
INotify: () => {
@INotifyMixin
class Foo implements INotify {
addListener(_: string, __: Listener, ___?: any): boolean {
Expand Down Expand Up @@ -34,5 +35,5 @@ describe("mixins", () => {
assert.deepStrictEqual((<any>foo)._listeners, {});
foo.notify({ id: "x", value: 3 });
assert.deepStrictEqual(res, { x: 1, [EVENT_ALL]: 2 });
});
},
});
54 changes: 30 additions & 24 deletions packages/args/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from "assert";
import { group } from "@thi.ng/testament";
import {
coerceInt,
flag,
Expand All @@ -19,8 +20,8 @@ import {
Tuple,
} from "../src";

describe("args", () => {
it("basic / string", () => {
group("args", {
"basic / string": () => {
assert.deepStrictEqual(
parse<{ a?: string }>({ a: string({}) }, ["--a", "a"], {
start: 0,
Expand Down Expand Up @@ -50,9 +51,9 @@ describe("args", () => {
showUsage: false,
})
);
});
},

it("flag", () => {
flag: () => {
assert.deepStrictEqual(
parse<{ a?: boolean }>({ a: flag({}) }, ["--a"], {
start: 0,
Expand All @@ -65,9 +66,9 @@ describe("args", () => {
}),
{ result: { a: false }, index: 0, done: true, rest: [] }
);
});
},

it("number", () => {
number: () => {
assert.deepStrictEqual(
parse<{ a?: number }>({ a: float({}) }, ["--a", "1.23"], {
start: 0,
Expand All @@ -92,9 +93,9 @@ describe("args", () => {
showUsage: false,
})
);
});
},

it("enum", () => {
enum: () => {
type E = "abc" | "xyz";
const opts: E[] = ["abc", "xyz"];
assert.deepStrictEqual(
Expand All @@ -113,9 +114,9 @@ describe("args", () => {
showUsage: false,
})
);
});
},

it("kv", () => {
kv: () => {
assert.deepStrictEqual(
parse<{ a?: KVDict }>(
{ a: kvPairs({}) },
Expand All @@ -135,7 +136,12 @@ describe("args", () => {
parse<{ a?: KVDict }>({ a: kvPairs({}, ":") }, ["--a", "foo:bar"], {
start: 0,
}),
{ result: { a: { foo: "bar" } }, index: 2, done: true, rest: [] }
{
result: { a: { foo: "bar" } },
index: 2,
done: true,
rest: [],
}
);
assert.throws(() =>
parse<{ a?: KVDict }>(
Expand All @@ -147,9 +153,9 @@ describe("args", () => {
}
)
);
});
},

it("kvMulti", () => {
kvMulti: () => {
assert.deepStrictEqual(
parse<{ a?: KVMultiDict }>(
{ a: kvPairsMulti({}) },
Expand All @@ -174,9 +180,9 @@ describe("args", () => {
rest: [],
}
);
});
},

it("json", () => {
json: () => {
assert.deepStrictEqual(
parse<{ a: any }>(
{ a: json<any, any>({}) },
Expand All @@ -187,9 +193,9 @@ describe("args", () => {
),
{ result: { a: { foo: [23] } }, index: 2, done: true, rest: [] }
);
});
},

it("number[]", () => {
"number[]": () => {
assert.deepStrictEqual(
parse<{ a?: number[] }>({ a: ints({}) }, ["--a", "1", "--a", "2"], {
start: 0,
Expand All @@ -206,9 +212,9 @@ describe("args", () => {
),
{ result: { a: [1, 2, 3, 4] }, index: 4, done: true, rest: [] }
);
});
},

it("tuple", () => {
tuple: () => {
const res = {
result: { a: new Tuple([1, 2, 3]) },
index: 2,
Expand All @@ -235,9 +241,9 @@ describe("args", () => {
),
res
);
});
},

it("stop early", () => {
"stop early": () => {
assert.deepStrictEqual(
parse<{ a?: number }>({ a: int({}) }, ["--a", "1", "foo"], {
start: 0,
Expand All @@ -254,9 +260,9 @@ describe("args", () => {
),
{ result: { a: 1 }, index: 3, done: false, rest: ["ignore"] }
);
});
},

it("long alias", () => {
"long alias": () => {
assert.deepStrictEqual(
parse<{ a?: string }>(
{ a: string({ alias: "aaa" }) },
Expand All @@ -267,5 +273,5 @@ describe("args", () => {
),
{ result: { a: "a" }, index: 2, done: true, rest: [] }
);
});
},
});
23 changes: 12 additions & 11 deletions packages/arrays/test/binary-search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FnO } from "@thi.ng/api";
import { group } from "@thi.ng/testament";
import * as assert from "assert";
import { binarySearch, bsEQ, bsGE, bsGT, bsLE, bsLT } from "../src";

Expand All @@ -14,20 +15,20 @@ const checkPred = (pred: FnO<number, number>, res: number[]) => {
}
};

describe("binarySearch", () => {
it("lt", () => {
group("binarySearch", {
lt: () => {
checkPred(bsLT, [-1, -1, 0, 0, 1, 3]);
});
it("le", () => {
},
le: () => {
checkPred(bsLE, [-1, 0, 0, 1, 1, 3]);
});
it("gt", () => {
},
gt: () => {
checkPred(bsGT, [0, 1, 1, 2, 2, -1]);
});
it("ge", () => {
},
ge: () => {
checkPred(bsGE, [0, 0, 1, 1, 2, -1]);
});
it("eq", () => {
},
eq: () => {
checkPred(bsEQ, [-1, 0, -1, 1, -1, -1]);
});
},
});
7 changes: 4 additions & 3 deletions packages/arrays/test/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as assert from "assert";
import { group } from "@thi.ng/testament";
import { arrayIterator } from "../src";

describe("arrayIterator", () => {
it("basics", () => {
group("arrayIterator", {
basics: () => {
assert.deepStrictEqual([...arrayIterator(null)], []);
assert.deepStrictEqual([...arrayIterator([])], []);
assert.deepStrictEqual([...arrayIterator([1])], [1]);
Expand All @@ -12,5 +13,5 @@ describe("arrayIterator", () => {
[...arrayIterator([1, 2, 3, 4], 3, -1)],
[4, 3, 2, 1]
);
});
},
});
Loading

0 comments on commit 8b582bc

Please sign in to comment.