| 7 | ) |
| 8 | |
| 9 | func 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 | |
| 45 | func TestBTreeDecreasing(t *testing.T) { |
| 46 | maxKeysCases := []int{4, 16} |