39 lines
637 B
Go
39 lines
637 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildingTree(t *testing.T) {
|
|
tree := NewStringyBTree("foo", 1).Insert("bar", 2).Insert("baz", 3).Insert("quuz", 4)
|
|
if tree.Get("foo") != 1 {
|
|
t.Fail()
|
|
}
|
|
if tree.Get("bar") != 2 {
|
|
t.Fail()
|
|
}
|
|
if tree.Get("baz") != 3 {
|
|
t.Fail()
|
|
}
|
|
if tree.Get("quuz") != 4 {
|
|
t.Fail()
|
|
}
|
|
tree.Insert("bar", 5)
|
|
if tree.Get("bar") != 5 {
|
|
t.Fail()
|
|
}
|
|
if tree.Get("zot") != nil {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
var r TreeNode
|
|
|
|
func BenchmarkInserts(b *testing.B) {
|
|
var result TreeNode
|
|
for n := 0; n < b.N; n++ {
|
|
NewStringyBTree("foo", 1).Insert("bar", 2).Insert("baz", 3).Insert("quuz", 4)
|
|
}
|
|
r = result
|
|
}
|