| 256 | } |
| 257 | |
| 258 | func TestTreeMinAndMax(t *testing.T) { |
| 259 | helper := func(tree TestTree[int], nums []int) { |
| 260 | ll := len(nums) |
| 261 | if _, ok := tree.Min(); ok { |
| 262 | t.Errorf("Error with Min method.") |
| 263 | } |
| 264 | if _, ok := tree.Max(); ok { |
| 265 | t.Errorf("Error with Max method.") |
| 266 | } |
| 267 | tree.Push(nums...) |
| 268 | if min, ok := tree.Min(); !ok || min != nums[0] { |
| 269 | t.Errorf("Error with Min method.") |
| 270 | } |
| 271 | if max, ok := tree.Max(); !ok || max != nums[ll-1] { |
| 272 | t.Errorf("Error with Max method.") |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | lens := []int{500, 1_000, 10_000} |
| 277 | for _, ll := range lens { |
| 278 | nums := rand.Perm(ll) |
| 279 | sort.Ints(nums) |
| 280 | |
| 281 | t.Run("Test Binary Search Tree", func(t *testing.T) { |
| 282 | helper(bt.NewBinarySearch[int](), nums) |
| 283 | }) |
| 284 | |
| 285 | t.Run("Test Red-Black Tree", func(t *testing.T) { |
| 286 | helper(bt.NewRB[int](), nums) |
| 287 | }) |
| 288 | |
| 289 | t.Run("Test AVL Tree", func(t *testing.T) { |
| 290 | helper(bt.NewAVL[int](), nums) |
| 291 | }) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | func TestTreeDepth(t *testing.T) { |
| 296 | t.Run("Test for Binary-Search Tree", func(t *testing.T) { |