-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.go
81 lines (71 loc) · 1.18 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
77
78
79
80
81
package btree
import (
"fmt"
"testing"
)
func TestTree_Get(t *testing.T) {
tr := &tree{
root: &node{
items: items{3},
children: children{
{
items: items{1, 2},
},
{
items: items{4, 5, 6},
},
},
},
}
_, ok := tr.Get(5)
if !ok {
t.Fatal("should get 5")
}
_, ok = tr.Get(7)
if ok {
t.Fatal("should not get 7")
}
}
func TestOther(t *testing.T) {
fmt.Println(5 / 2)
}
func insertAt(items []int, i, key int) []int {
items = append(items, -1)
copy(items[i+1:], items[i:len(items)-1])
items[i] = key
return items
}
func TestInsertAt(t *testing.T) {
items := []int{1, 3, 4}
fmt.Println(insertAt(items, 1, 2))
}
func TestTree_Add(t *testing.T) {
tr := &tree{
root: &node{
items: items{3, 6, 9, 12},
children: []*node{
{items: items{1, 2}},
{items: items{4, 5}},
{items: items{7, 8}},
{items: items{10, 11}},
{items: items{13, 14, 15, 16}},
},
},
}
tr.Add(17)
fmt.Println(tr)
}
func TestTree_Delete(t *testing.T) {
tr := &tree{
root: &node{
items: items{3, 6},
children: children{
{items: items{1, 2}},
{items: items{4, 5}},
{items: items{7, 8}},
},
},
}
tr.Delete(4)
fmt.Println(tr)
}