-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtreeNode.test.ts
102 lines (89 loc) · 2.54 KB
/
treeNode.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {TreeNodeData} from "../types";
import anyTest, { TestInterface } from "ava";
import TreeNode from "../src/TreeNode";
const NAMESPACE = "TreeNode: ";
const test = anyTest as TestInterface<{
parentNode: TreeNode<TreeNodeData>;
childNode1: TreeNode<TreeNodeData>;
childNode2: TreeNode<TreeNodeData>;
childNode3: TreeNode<TreeNodeData>;
}>;
test.before(t => {
const parentNode = new TreeNode({
id: 0,
content: {
title: "parent title",
data: ["parent data"]
}
});
const childNode1 = new TreeNode(
{
id: 1,
content: {
title: "child title 1",
data: ["child data 1"]
}
},
parentNode
);
const childNode2 = new TreeNode(
{
id: 2,
content: {
title: "child title 2",
data: ["child data 2"]
}
},
parentNode
);
const childNode3 = new TreeNode(
{
id: 3,
content: {
title: "child title 3",
data: ["child data 3"]
}
},
parentNode
);
parentNode.children = [childNode1, childNode2, childNode3];
t.context = {
parentNode,
childNode1,
childNode2,
childNode3
};
});
test(`${NAMESPACE}test for isLeaf`, t => {
t.true(t.context.childNode1.isLeaf());
t.false(t.context.parentNode.isLeaf());
});
test(`${NAMESPACE}test for isLeftMost`, t => {
t.true(t.context.childNode1.isLeftMost());
});
test(`${NAMESPACE}test for isRightMost`, t => {
t.true(t.context.childNode3.isRightMost());
});
test(`${NAMESPACE}test for getPreviousSibling`, t => {
t.is(t.context.childNode3.getPreviousSibling(), t.context.childNode2);
t.is(t.context.childNode1.getPreviousSibling(), null);
t.is(t.context.parentNode.getPreviousSibling(), null);
});
test(`${NAMESPACE}test for getNextSibling`, t => {
t.is(t.context.childNode1.getNextSibling(), t.context.childNode2);
t.is(t.context.childNode3.getNextSibling(), null);
t.is(t.context.parentNode.getNextSibling(), null);
});
test(`${NAMESPACE}test for getLeftMostSibling`, t => {
t.is(t.context.childNode1.getLeftMostSibling(), t.context.childNode1);
t.is(t.context.childNode3.getLeftMostSibling(), t.context.childNode1);
t.is(t.context.parentNode.getLeftMostSibling(), null);
});
test(`${NAMESPACE}test for getLeftMostChild`, t => {
t.is(t.context.parentNode.getLeftMostChild(), t.context.childNode1);
t.is(t.context.childNode3.getLeftMostChild(), null);
});
test(`${NAMESPACE}test for getRightMostChild`, t => {
t.is(t.context.parentNode.getRightMostChild(), t.context.childNode3);
t.is(t.context.childNode3.getRightMostChild(), null);
});