-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtrees_test.go
65 lines (54 loc) · 1.22 KB
/
trees_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
package model
import (
"reflect"
"strings"
"testing"
)
func TestChunks(t *testing.T) {
a := make([]int, 20)
for i := range a {
a[i] = i
}
chunks := splitInts(a, 3)
if len(chunks) != 7 {
t.Errorf("expected 7 chunks, got %d", len(chunks))
}
chunks = splitInts(a, 4)
if len(chunks) != 5 {
t.Errorf("expected 5 chunks, got %d", len(chunks))
}
b := make([]string, 18)
for i := range b {
b[i] = strings.Repeat("u", i)
}
chunks2 := splitStrings(b, 3)
if len(chunks2) != 6 {
t.Errorf("expected 6 chunks, got %d", len(chunks))
}
chunks2 = splitStrings(b, 4)
if len(chunks2) != 5 {
t.Errorf("expected 5 chunks, got %d", len(chunks))
}
}
func TestIDTree(t *testing.T) {
m := make(map[string]*StructureElement)
for i := range [1000]int{} {
m[strings.Repeat("s", i)] = new(StructureElement)
}
tree := NewIDTree(m)
m2 := tree.LookupTable()
if !reflect.DeepEqual(m, m2) {
t.Errorf("expected %v, got %v", m, m2)
}
}
func TestParentTree(t *testing.T) {
m := make(map[int]NumToParent)
for i := range [1000]int{} {
m[i] = NumToParent{Num: i, Parent: new(StructureElement)}
}
tree := NewParentTree(m)
m2 := tree.LookupTable()
if !reflect.DeepEqual(m, m2) {
t.Errorf("expected %v, got %v", m, m2)
}
}