-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrefixTree.test.ts
61 lines (58 loc) · 2.08 KB
/
PrefixTree.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { assertEquals } from "../deps.ts";
import {
PrefixTreeInsert,
} from "../design-add-and-search-words-data-structure/PrefixTreeInsert.ts";
import { PrefixTree } from "../implement-trie-prefix-tree/PrefixTree.ts";
import { examples } from "./examples.ts";
import { PrefixTreeClear } from "./PrefixTreeClear.ts";
import { PrefixTreeForEach } from "./PrefixTreeForEach.ts";
import { PrefixTreeFromArray } from "./PrefixTreeFromArray.ts";
import { PrefixTreeToArray1 } from "./PrefixTreeToArray1.ts";
// import { PrefixTreeToArray2 } from "./PrefixTreeToArray2.ts";
Deno.test("Prefix-Tree-from-array-for-each-PrefixTreeToArray1", () => {
const words = [
"1",
"32",
"123",
"21",
"222",
"132",
"111",
"312",
"hello",
"world",
"ffff",
];
const tree = PrefixTreeFromArray(words);
const left = new Set(words);
const right = new Set(PrefixTreeToArray1(tree));
// console.log(left, right);
assertEquals(left, right);
const temp: string[] = [];
PrefixTreeForEach(tree, (w) => temp.push(w));
assertEquals(left, new Set(temp));
});
Deno.test("Prefix-Tree-Insert-PrefixTreeToArray1-clear", () => {
const words = examples;
const tree = PrefixTree();
words.forEach((word) => PrefixTreeInsert(tree, word));
const left = new Set(words);
const right = new Set(PrefixTreeToArray1(tree));
// console.log(left, right);
assertEquals(left, right);
assertEquals([], PrefixTreeToArray1(PrefixTree()));
PrefixTreeClear(tree);
assertEquals([], PrefixTreeToArray1(tree));
});
// Deno.test("Prefix-Tree-Insert-PrefixTreeToArray2-clear", () => {
// const words = examples;
// const tree = PrefixTree();
// words.forEach((word) => PrefixTreeInsert(tree, word));
// const left = new Set(words);
// const right = new Set(PrefixTreeToArray2(tree));
// // console.log(left, right);
// assertEquals(left, right);
// assertEquals([], PrefixTreeToArray2(PrefixTree()));
// PrefixTreeClear(tree);
// assertEquals([], PrefixTreeToArray2(tree));
// });