-
Notifications
You must be signed in to change notification settings - Fork 85
/
tree_test.go
76 lines (70 loc) · 1.27 KB
/
tree_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 opc
import (
"testing"
)
func testingCreateNewTree() *Tree {
root := Tree{
Name: "root",
Parent: nil,
Branches: []*Tree{},
Leaves: []Leaf{
Leaf{
Name: "bandwidth",
Tag: "bandwidth",
},
},
}
options := Tree{
Name: "options",
Parent: &root,
Branches: []*Tree{},
Leaves: []Leaf{
Leaf{
Name: "frequency",
Tag: "options.frequency",
},
Leaf{
Name: "amplitute",
Tag: "options.amplitude",
},
},
}
numeric := Tree{
Name: "numeric",
Parent: &root,
Branches: []*Tree{},
Leaves: []Leaf{
Leaf{
Name: "sin",
Tag: "numeric.sin",
},
Leaf{
Name: "cos",
Tag: "numeric.cos",
},
Leaf{
Name: "tan",
Tag: "numeric.tan",
},
},
}
root.Branches = append(root.Branches, &options, &numeric)
return &root
}
func TestTreeExtractBranchByName(t *testing.T) {
tree := testingCreateNewTree()
subtree := ExtractBranchByName(tree, "numeric")
if subtree == nil {
t.Fatal("subtree not correctly extracted")
}
if len(CollectTags(subtree)) != 3 {
t.Fatal("subtree not correctly extracted")
}
}
func TestTreeCollectTags(t *testing.T) {
tree := testingCreateNewTree()
collection := CollectTags(tree)
if len(collection) != 6 {
t.Fatal("not enough tags collected")
}
}