| 107 | } |
| 108 | |
| 109 | func TestTreeInOrder(t *testing.T) { |
| 110 | lens := []int{100, 1_000, 10_000, 100_000} |
| 111 | for _, ll := range lens { |
| 112 | nums := rand.Perm(ll) |
| 113 | |
| 114 | t.Run("Test Binary Search Tree", func(t *testing.T) { |
| 115 | bsTree := bt.NewBinarySearch[int]() |
| 116 | bsTree.Push(nums...) |
| 117 | if ret := bsTree.InOrder(); !sort.IntsAreSorted(ret) { |
| 118 | t.Errorf("Error with InOrder") |
| 119 | } |
| 120 | }) |
| 121 | |
| 122 | t.Run("Test Red-Black Tree", func(t *testing.T) { |
| 123 | rbTree := bt.NewRB[int]() |
| 124 | rbTree.Push(nums...) |
| 125 | if ret := rbTree.InOrder(); !sort.IntsAreSorted(ret) { |
| 126 | t.Errorf("Error with InOrder") |
| 127 | } |
| 128 | }) |
| 129 | |
| 130 | t.Run("Test AVL Tree", func(t *testing.T) { |
| 131 | avlTree := bt.NewAVL[int]() |
| 132 | avlTree.Push(nums...) |
| 133 | if ret := avlTree.InOrder(); !sort.IntsAreSorted(ret) { |
| 134 | t.Errorf("Error with InOrder") |
| 135 | } |
| 136 | }) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func TestTreePostOrder(t *testing.T) { |
| 141 | t.Run("Test for Binary-Search Tree", func(t *testing.T) { |