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

Function TestBTreeDecreasing

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

Source from the content-addressed store, hash-verified

43}
44
45func TestBTreeDecreasing(t *testing.T) {
46 maxKeysCases := []int{4, 16}
47 sizes := []int{100, 1000}
48 for _, maxKeys := range maxKeysCases {
49 for _, size := range sizes {
50 tree := bt.NewBTree[int](maxKeys)
51 if tree.Search(0) {
52 t.Errorf("Tree expected to contain 0")
53 }
54 for i := size - 1; i >= 0; i-- {
55 tree.Insert(i)
56 }
57 for i := 0; i < size; i++ {
58 if !tree.Search(i) {
59 t.Errorf("Tree expected to contain %d", i)
60 }
61 }
62 if tree.Search(size + 1) {
63 t.Errorf("Tree not expected to contain %d", size+1)
64 }
65
66 for i := 0; i < size; i += 5 {
67 tree.Delete(i)
68 }
69 for i := 0; i < size; i++ {
70 hasKey := tree.Search(i)
71 if i%5 == 0 && hasKey {
72 t.Errorf("Tree not expected to contain %d", i)
73 } else if i%5 != 0 && !hasKey {
74 t.Errorf("Tree expected to contain %d", i)
75 }
76 }
77 }
78 }
79}
80
81func TestBTreeRandom(t *testing.T) {
82 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