Skip to content

Commit e3085e4

Browse files
refactor: update all tests (packages A-S)
1 parent 1cb3c49 commit e3085e4

File tree

207 files changed

+9616
-11087
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+9616
-11087
lines changed

packages/adapt-dpi/test/main.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { expect, test } from "bun:test";
22
// import {} from "../src/index.js";
33

4-
test("adapt-dpi", () => {});
4+
test.todo("adapt-dpi", () => {});

packages/associative/test/multitrie.test.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { expect, test } from "bun:test";
1+
import { beforeEach, expect, test } from "bun:test";
22
import { MultiTrie } from "../src/index.js";
33

44
let root: MultiTrie<string, string>;
55

6-
const init = () => {
6+
beforeEach(() => {
77
root = new MultiTrie();
88
root.add("hey", "en");
99
root.add("hello", "en");
@@ -12,10 +12,9 @@ const init = () => {
1212
root.add("hola", "es");
1313
root.add("hold", "en");
1414
root.add("hej", "se");
15-
};
15+
});
1616

1717
test("keys", () => {
18-
init();
1918
expect(new Set(root.keys())).toEqual(
2019
new Set(["hey", "hello", "hallo", "hallo", "hola", "hold", "hej"])
2120
);
@@ -31,7 +30,6 @@ test("keys", () => {
3130
});
3231

3332
test("keys (words)", () => {
34-
init();
3533
const t = new MultiTrie<string[], string>();
3634
t.add("foo bar baz".split(" "), "a");
3735
t.add("foo boo zoo".split(" "), "b");
@@ -41,15 +39,13 @@ test("keys (words)", () => {
4139
});
4240

4341
test("values", () => {
44-
init();
4542
expect(new Set(root.values())).toEqual(
4643
new Set(["en", "es", "de", "de-at", "se"])
4744
);
4845
expect(new Set(root.find("he")!.values())).toEqual(new Set(["en", "se"]));
4946
});
5047

5148
test("delete", () => {
52-
init();
5349
expect(root.delete("he")).toBeTrue();
5450
expect(new Set(root.keys())).toEqual(new Set(["hola", "hold", "hallo"]));
5551
expect(root.delete("hallo", "de")).toBeTrue();
@@ -59,7 +55,6 @@ test("delete", () => {
5955
});
6056

6157
test("known prefix", () => {
62-
init();
6358
expect(root.knownPrefix("hole")).toEqual(["h", "o", "l"]);
6459
expect(root.knownPrefix("whole")).toEqual([]);
6560
});

packages/associative/test/sortedmap.test.ts

+3-24
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import { shuffle } from "@thi.ng/arrays";
22
import { equiv } from "@thi.ng/equiv";
33
import { XsAdd } from "@thi.ng/random";
44
import { range, repeat, zip } from "@thi.ng/transducers";
5-
import { expect, test } from "bun:test";
5+
import { beforeEach, expect, test } from "bun:test";
66
import { SortedMap, defSortedMap } from "../src/index.js";
77

88
let m: SortedMap<any, any>;
99

10-
const init = () => {
10+
beforeEach(() => {
1111
m = defSortedMap({ a: 1, b: 2, c: 3 });
12-
};
12+
});
1313

1414
test("size", () => {
15-
init();
1615
expect(m.size).toBe(3);
1716
m.set("a", 10);
1817
expect(m.size).toBe(3);
@@ -25,7 +24,6 @@ test("size", () => {
2524
});
2625

2726
test("clear", () => {
28-
init();
2927
m.clear();
3028
expect(m.size).toBe(0);
3129
expect([...m.entries()]).toEqual([]);
@@ -34,26 +32,22 @@ test("clear", () => {
3432
});
3533

3634
test("empty", () => {
37-
init();
3835
const m2 = m.empty();
3936
expect(m.size).toBe(3);
4037
expect(m2.size).toBe(0);
4138
expect([...m2.entries()]).toEqual([]);
4239
});
4340

4441
test("copy", () => {
45-
init();
4642
expect(m.copy()).toEqual(m);
4743
});
4844

4945
test("equiv", () => {
50-
init();
5146
expect(equiv(m.copy(), m)).toBeTrue();
5247
expect(equiv(m, new SortedMap<any, any>())).toBeFalse();
5348
});
5449

5550
test("has", () => {
56-
init();
5751
expect(m.has("a")).toBeTrue();
5852
expect(m.has("b")).toBeTrue();
5953
expect(m.has("c")).toBeTrue();
@@ -63,14 +57,12 @@ test("has", () => {
6357
});
6458

6559
test("first", () => {
66-
init();
6760
expect(["a", 1]).toEqual(m.first()!);
6861
m.set("A", 10);
6962
expect(["A", 10]).toEqual(m.first()!);
7063
});
7164

7265
test("get", () => {
73-
init();
7466
expect(m.get("a")).toBe(1);
7567
expect(m.get("b")).toBe(2);
7668
expect(m.get("c")).toBe(3);
@@ -80,7 +72,6 @@ test("get", () => {
8072
});
8173

8274
test("entries", () => {
83-
init();
8475
expect([...m]).toEqual([
8576
["a", 1],
8677
["b", 2],
@@ -93,7 +84,6 @@ test("entries", () => {
9384
// },
9485

9586
test("entries a", () => {
96-
init();
9787
expect([...m.entries("a")]).toEqual([
9888
["a", 1],
9989
["b", 2],
@@ -106,7 +96,6 @@ test("entries a", () => {
10696
// },
10797

10898
test("entries aa", () => {
109-
init();
11099
expect([...m.entries("aa")]).toEqual([
111100
["b", 2],
112101
["c", 3],
@@ -118,7 +107,6 @@ test("entries aa", () => {
118107
// },
119108

120109
test("entries bb", () => {
121-
init();
122110
expect([...m.entries("bb")]).toEqual([["c", 3]]);
123111
});
124112

@@ -127,7 +115,6 @@ test("entries bb", () => {
127115
// },
128116

129117
test("entries c", () => {
130-
init();
131118
expect([...m.entries("c")]).toEqual([["c", 3]]);
132119
});
133120

@@ -136,7 +123,6 @@ test("entries c", () => {
136123
// },
137124

138125
test("entries 0", () => {
139-
init();
140126
expect([...m.entries("0")]).toEqual([
141127
["a", 1],
142128
["b", 2],
@@ -149,7 +135,6 @@ test("entries 0", () => {
149135
// });
150136

151137
test("entries d", () => {
152-
init();
153138
expect([...m.entries("d")]).toEqual([]);
154139
});
155140

@@ -158,23 +143,20 @@ test("entries d", () => {
158143
// },
159144

160145
test("keys", () => {
161-
init();
162146
expect([...m.keys()]).toEqual(["a", "b", "c"]);
163147
m.set("aa", 0);
164148
m.set("d", 0);
165149
expect([...m.keys()]).toEqual(["a", "aa", "b", "c", "d"]);
166150
});
167151

168152
test("values", () => {
169-
init();
170153
expect([...m.values()]).toEqual([1, 2, 3]);
171154
m.set("aa", 0);
172155
m.set("d", 0);
173156
expect([...m.values()]).toEqual([1, 0, 2, 3, 0]);
174157
});
175158

176159
test("comparator", () => {
177-
init();
178160
m = defSortedMap(
179161
{ a: 1, b: 2, c: 3 },
180162
{
@@ -189,7 +171,6 @@ test("comparator", () => {
189171
});
190172

191173
test("fuzz", () => {
192-
init();
193174
const keys = [...range(32)];
194175
for (let i = 0; i < 1000; i++) {
195176
m = new SortedMap(zip(shuffle(keys.slice()), repeat(1)));
@@ -198,7 +179,6 @@ test("fuzz", () => {
198179
});
199180

200181
test("fuzzSetDelete", () => {
201-
init();
202182
const s = defSortedMap<number, number>(null, {
203183
compare: (a, b) => a - b,
204184
});
@@ -211,7 +191,6 @@ test("fuzzSetDelete", () => {
211191
});
212192

213193
test("updateValue", () => {
214-
init();
215194
m = defSortedMap(
216195
[
217196
["one", 1],

packages/associative/test/sparseset.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isSet } from "@thi.ng/checks";
22
import { equiv } from "@thi.ng/equiv";
3-
import { expect, test } from "bun:test";
3+
import { beforeEach, expect, test } from "bun:test";
44
import {
55
SparseSet16,
66
SparseSet32,
@@ -10,12 +10,11 @@ import {
1010

1111
let set: SparseSet8;
1212

13-
const init = () => {
13+
beforeEach(() => {
1414
set = new SparseSet8(8);
15-
};
15+
});
1616

1717
test("factory / max value", () => {
18-
init();
1918
let a = defSparseSet(0x100);
2019
a.into([0xff, 0x100]);
2120
expect(a instanceof SparseSet8).toBeTrue();
@@ -33,14 +32,12 @@ test("factory / max value", () => {
3332
});
3433

3534
test("ctor(n)", () => {
36-
init();
3735
expect(isSet(set)).toBeTrue();
3836
expect(set.size).toBe(0);
3937
expect(set.capacity).toBe(8);
4038
});
4139

4240
test("ctor(arrays)", () => {
43-
init();
4441
const d = new Uint8Array(8);
4542
const s = new Uint8Array(8);
4643
set = new SparseSet8(d, s);
@@ -50,7 +47,6 @@ test("ctor(arrays)", () => {
5047
});
5148

5249
test("add", () => {
53-
init();
5450
expect(
5551
equiv(
5652
set.into([1, 4, 3, 7, 9, 2, 0, 1, 2]),
@@ -60,7 +56,6 @@ test("add", () => {
6056
});
6157

6258
test("delete", () => {
63-
init();
6459
set.into([1, 4, 3, 7, 9, 2, 0, 1, 2]);
6560
expect(set.delete(4)).toBeTrue();
6661
expect(equiv(set, new Set([0, 1, 2, 3, 7]))).toBeTrue();
@@ -75,7 +70,6 @@ test("delete", () => {
7570
});
7671

7772
test("has", () => {
78-
init();
7973
expect(set.has(0)).toBeFalse();
8074
set.add(0);
8175
set.add(0);
+13-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import { expect, test } from "bun:test";
1+
import { beforeEach, expect, test } from "bun:test";
22
import { TrieMap } from "../src/index.js";
33

44
let root: TrieMap<string>;
55

6-
const init = () =>
7-
(root = new TrieMap([
8-
["hey", "en"],
9-
["hello", "en"],
10-
["hallo", "de"],
11-
["hallo", "de-at"],
12-
["hola", "es"],
13-
["hold", "en"],
14-
["hej", "se"],
15-
]));
6+
beforeEach(
7+
() =>
8+
(root = new TrieMap([
9+
["hey", "en"],
10+
["hello", "en"],
11+
["hallo", "de"],
12+
["hallo", "de-at"],
13+
["hola", "es"],
14+
["hold", "en"],
15+
["hej", "se"],
16+
]))
17+
);
1618

1719
test("keys", () => {
18-
init();
1920
expect(new Set(root.keys())).toEqual(
2021
new Set(["hey", "hello", "hallo", "hallo", "hola", "hold", "hej"])
2122
);
@@ -25,15 +26,13 @@ test("keys", () => {
2526
});
2627

2728
test("values", () => {
28-
init();
2929
expect(new Set(root.values())).toEqual(
3030
new Set(["en", "es", "de-at", "se"])
3131
);
3232
expect(new Set(root.find("he")!.values())).toEqual(new Set(["en", "se"]));
3333
});
3434

3535
test("delete", () => {
36-
init();
3736
expect(root.delete("he")).toBeTrue();
3837
expect(new Set(root.keys())).toEqual(new Set(["hola", "hold", "hallo"]));
3938
expect(root.delete("hallo")).toBeTrue();
@@ -43,13 +42,11 @@ test("delete", () => {
4342
});
4443

4544
test("known prefix", () => {
46-
init();
4745
expect(root.knownPrefix("hole")).toEqual("hol");
4846
expect(root.knownPrefix("whole")).toBeUndefined();
4947
});
5048

5149
test("suffixes", () => {
52-
init();
5350
expect([...root.suffixes("he")]).toEqual(["j", "llo", "y"]);
5451
expect([...root.suffixes("he", true)]).toEqual(["hej", "hello", "hey"]);
5552
});

0 commit comments

Comments
 (0)