| 81 | } |
| 82 | |
| 83 | func TestAVL(t *testing.T) { |
| 84 | tree = bt.NewAVL[int]() |
| 85 | |
| 86 | if tree.Empty() { |
| 87 | t.Log("AVL Tree is empty now.") |
| 88 | } |
| 89 | |
| 90 | tree.Push(1, 4, 10) |
| 91 | tree.Push(-8) |
| 92 | nums := []int{87, 18, 10, -34} |
| 93 | tree.Push(nums...) |
| 94 | tree.Push(4) // duplicate key, dismiss it |
| 95 | |
| 96 | if tree.Has(4) { |
| 97 | t.Logf("There is a node of 4") |
| 98 | } |
| 99 | |
| 100 | if n, ok := tree.Get(10); ok { |
| 101 | t.Logf("node of 10: %T", n) |
| 102 | } |
| 103 | |
| 104 | if ret, ok := tree.Min(); ok { |
| 105 | t.Logf("tree.Min() = %v", ret) |
| 106 | } |
| 107 | |
| 108 | if ret, ok := tree.Max(); ok { |
| 109 | t.Logf("tree.Max() = %v", ret) |
| 110 | } |
| 111 | |
| 112 | if ret, ok := tree.Predecessor(1); ok { |
| 113 | t.Logf("tree.Preducessor(1) = %v", ret) |
| 114 | } |
| 115 | |
| 116 | if ret, ok := tree.Successor(18); ok { |
| 117 | t.Logf("tree.Successor(18) = %v", ret) |
| 118 | } |
| 119 | |
| 120 | fmt.Println(tree.InOrder()) |
| 121 | fmt.Println(tree.AccessNodesByLayer()) |
| 122 | |
| 123 | tree.Delete(18) |
| 124 | fmt.Println("Delete 18") |
| 125 | fmt.Println(tree.InOrder()) |
| 126 | } |
| 127 | |
| 128 | func TestRB(t *testing.T) { |
| 129 | tree = bt.NewRB[int]() |