-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtree_example_test.go
85 lines (75 loc) · 1.47 KB
/
btree_example_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
82
83
84
85
package btree_test
import (
"github.com/droxer/btree"
"os"
"testing"
)
type item int
func (i item) Less(other btree.Item) bool {
return i < other.(item)
}
func TestGet(t *testing.T) {
bt := btree.New(2)
bt.Insert(item(4))
bt.Insert(item(6))
bt.Insert(item(8))
bt.Insert(item(18))
bt.Insert(item(20))
bt.Insert(item(22))
bt.Insert(item(24))
bt.Insert(item(26))
bt.Insert(item(28))
bt.Insert(item(30))
if bt.Get(item(11)) != nil {
t.Fatalf("expected is nil, actual is %v", bt.Get(item(7)))
}
if bt.Get(item(8)) != item(8) {
t.Fatalf("expected is 5, actual is %v", bt.Get(item(7)))
}
}
func ExampleInsert() {
bt := btree.New(2)
bt.Insert(item(4))
bt.Insert(item(6))
bt.Insert(item(8))
bt.Insert(item(18))
bt.Insert(item(20))
bt.Insert(item(22))
bt.Insert(item(24))
bt.Insert(item(26))
bt.Insert(item(28))
bt.Insert(item(30))
bt.Insert(item(19))
bt.Insert(item(21))
bt.Print(os.Stdout)
// Output: NODE:[18]
// NODE:[6]
// NODE:[4]
// NODE:[8]
// NODE:[22 26]
// NODE:[19 20 21]
// NODE:[24]
// NODE:[28 30]
}
func ExampleDelete() {
bt := btree.New(2)
bt.Insert(item(2))
bt.Insert(item(4))
bt.Insert(item(6))
bt.Insert(item(8))
bt.Insert(item(18))
bt.Insert(item(20))
bt.Insert(item(22))
bt.Insert(item(24))
bt.Insert(item(26))
bt.Insert(item(28))
bt.Delete(item(4))
bt.Print(os.Stdout)
// Output: NODE:[20]
// NODE:[8]
// NODE:[2 6]
// NODE:[18]
// NODE:[24]
// NODE:[22]
// NODE:[26 28]
}