2021-07-25 23:29:13 +00:00
|
|
|
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()
|
|
|
|
}
|
2021-07-25 23:52:31 +00:00
|
|
|
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
|
2021-07-25 23:29:13 +00:00
|
|
|
}
|