| 121 | } |
| 122 | |
| 123 | func TestRBTreeString(t *testing.T) { |
| 124 | tree := bt.NewRB[string]() |
| 125 | |
| 126 | if tree.Has("Golang") { |
| 127 | t.Errorf("Error with Has when T is string.") |
| 128 | } |
| 129 | |
| 130 | strs := []string{"Hello", "World", "Golang", "Python", "Rust", "C", "JavaScript", "Haskell", "Pascal", "ZZ"} |
| 131 | for _, str := range strs { |
| 132 | tree.Push(str) |
| 133 | } |
| 134 | |
| 135 | if !tree.Has("Golang") { |
| 136 | t.Errorf("Error with Has when T is string.") |
| 137 | } |
| 138 | |
| 139 | if tree.Has("Pasc") { |
| 140 | t.Errorf("Error with Has when T is string.") |
| 141 | } |
| 142 | |
| 143 | if ok := tree.Delete("Hello"); !ok { |
| 144 | t.Errorf("Error with Delete when T is string.") |
| 145 | } |
| 146 | |
| 147 | if ok := tree.Delete("Pasc"); ok { |
| 148 | t.Errorf("Error with Delete when T is string.") |
| 149 | } |
| 150 | |
| 151 | if tree.Has("Hello") { |
| 152 | t.Errorf("Error with Has when T is string.") |
| 153 | } |
| 154 | |
| 155 | ret := tree.InOrder() |
| 156 | if !sort.StringsAreSorted(ret) { |
| 157 | t.Errorf("Error with Push when T is string") |
| 158 | } |
| 159 | |
| 160 | if ret, ok := tree.Min(); !ok || ret != "C" { |
| 161 | t.Errorf("Error with Min when T is string") |
| 162 | } |
| 163 | |
| 164 | if ret, ok := tree.Max(); !ok || ret != "ZZ" { |
| 165 | t.Errorf("Error with Max when T is string") |
| 166 | } |
| 167 | } |