|
|
|
@ -74,6 +74,52 @@ func TestBTreeGet2(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBTreeGet3(t *testing.T) {
|
|
|
|
|
tree := NewWithIntComparator(3)
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.Size(); actualValue != 0 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.GetNode(2).Size(); actualValue != 0 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree.Put(1, "x") // 1->x
|
|
|
|
|
tree.Put(2, "b") // 1->x, 2->b (in order)
|
|
|
|
|
tree.Put(1, "a") // 1->a, 2->b (in order, replacement)
|
|
|
|
|
tree.Put(3, "c") // 1->a, 2->b, 3->c (in order)
|
|
|
|
|
tree.Put(4, "d") // 1->a, 2->b, 3->c, 4->d (in order)
|
|
|
|
|
tree.Put(5, "e") // 1->a, 2->b, 3->c, 4->d, 5->e (in order)
|
|
|
|
|
tree.Put(6, "f") // 1->a, 2->b, 3->c, 4->d, 5->e, 6->f (in order)
|
|
|
|
|
tree.Put(7, "g") // 1->a, 2->b, 3->c, 4->d, 5->e, 6->f, 7->g (in order)
|
|
|
|
|
|
|
|
|
|
// BTree
|
|
|
|
|
// 1
|
|
|
|
|
// 2
|
|
|
|
|
// 3
|
|
|
|
|
// 4
|
|
|
|
|
// 5
|
|
|
|
|
// 6
|
|
|
|
|
// 7
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.Size(); actualValue != 7 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 7)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.GetNode(2).Size(); actualValue != 3 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 3)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.GetNode(4).Size(); actualValue != 7 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 7)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if actualValue := tree.GetNode(8).Size(); actualValue != 0 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBTreePut1(t *testing.T) {
|
|
|
|
|
// https://upload.wikimedia.org/wikipedia/commons/3/33/B_tree_insertion_example.png
|
|
|
|
|
tree := NewWithIntComparator(3)
|
|
|
|
|