-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode_test.go
76 lines (66 loc) · 1.71 KB
/
node_test.go
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
package gtree
import (
"testing"
)
func TestNode_IsDirectlyUnder(t *testing.T) {
tests := map[string]struct {
parent *Node
child *Node
want bool
}{
"true": {newNode("p", uint(1), uint(1)), newNode("c", uint(2), uint(2)), true},
"false": {newNode("c", uint(2), uint(1)), newNode("p", uint(1), uint(2)), false},
"false(argument node is nil)": {nil, newNode("c", uint(2), uint(2)), false},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
got := tt.child.isDirectlyUnder(tt.parent)
if got != tt.want {
t.Errorf("\ngot: \n%t\nwant: \n%t", got, tt.want)
}
})
}
}
func TestNode_IsLastOfHierarchy(t *testing.T) {
trueNode := func() *Node {
parent := newNode("p", uint(1), uint(1))
child := newNode("c", uint(2), uint(2))
parent.addChild(child)
child.setParent(parent)
return child
}
falseNode := func() *Node {
parent := newNode("p", uint(1), uint(1))
child1 := newNode("c1", uint(2), uint(2))
child2 := newNode("c2", uint(2), uint(3))
parent.addChild(child1)
child1.setParent(parent)
parent.addChild(child2)
child2.setParent(parent)
return child1
}
falseNodeNotSetParent := func() *Node {
child := newNode("c", uint(2), uint(2))
return child
}
tests := map[string]struct {
node *Node
want bool
}{
"true": {trueNode(), true},
"false": {falseNode(), false},
"false(not set parent)": {falseNodeNotSetParent(), false},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
got := tt.node.isLastOfHierarchy()
if got != tt.want {
t.Errorf("\ngot: \n%t\nwant: \n%t", got, tt.want)
}
})
}
}