MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestBTreeIncreasing

Function TestBTreeIncreasing

structure/tree/btree_test.go:9–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestBTreeIncreasing(t *testing.T) {
10 maxKeysCases := []int{4, 16}
11 sizes := []int{100, 0xBA5, 0xF00}
12 for _, maxKeys := range maxKeysCases {
13 for _, size := range sizes {
14 tree := bt.NewBTree[int](maxKeys)
15 if tree.Search(0) {
16 t.Errorf("Tree expected to contain 0")
17 }
18 for i := 0; i < size; i++ {
19 tree.Insert(i)
20 }
21 for i := 0; i < size; i++ {
22 if !tree.Search(i) {
23 t.Errorf("Tree expected to contain %d", i)
24 }
25 }
26 if tree.Search(size + 1) {
27 t.Errorf("Tree not expected to contain %d", size+1)
28 }
29
30 for i := 0; i < size; i += 5 {
31 tree.Delete(i)
32 }
33 for i := 0; i < size; i++ {
34 hasKey := tree.Search(i)
35 if i%5 == 0 && hasKey {
36 t.Errorf("Tree not expected to contain %d", i)
37 } else if i%5 != 0 && !hasKey {
38 t.Errorf("Tree expected to contain %d", i)
39 }
40 }
41 }
42 }
43}
44
45func TestBTreeDecreasing(t *testing.T) {
46 maxKeysCases := []int{4, 16}

Callers

nothing calls this directly

Calls 3

InsertMethod · 0.65
DeleteMethod · 0.65
SearchMethod · 0.45

Tested by

no test coverage detected