(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestTreeLevelOrder(t *testing.T) { |
| 200 | t.Run("Test for Binary-Search Tree", func(t *testing.T) { |
| 201 | tests := []struct { |
| 202 | input []int |
| 203 | want []int |
| 204 | }{ |
| 205 | {[]int{90, 80, 100, 70, 85, 95, 105}, []int{90, 80, 100, 70, 85, 95, 105}}, |
| 206 | {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, |
| 207 | []int{90, 80, 100, 70, 85, 95, 105, 1, 71, 21, 31, 41, 51, 61}}, |
| 208 | {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}}, |
| 209 | } |
| 210 | for i, tt := range tests { |
| 211 | tree := bt.NewBinarySearch[int]() |
| 212 | tree.Push(tt.input...) |
| 213 | if ret := tree.LevelOrder(); !reflect.DeepEqual(ret, tt.want) { |
| 214 | t.Errorf("#%d Error with LevelOrder", i) |
| 215 | } |
| 216 | } |
| 217 | }) |
| 218 | |
| 219 | t.Run("Test for AVL Tree", func(t *testing.T) { |
| 220 | tests := []struct { |
| 221 | input []int |
| 222 | want []int |
| 223 | }{ |
| 224 | {[]int{90, 80, 100, 70, 85, 95, 105}, []int{90, 80, 100, 70, 85, 95, 105}}, |
| 225 | {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, |
| 226 | []int{70, 41, 90, 21, 51, 80, 100, 1, 31, 61, 71, 85, 95, 105}}, |
| 227 | {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{7, 3, 9, 2, 5, 8, 10, 1, 4, 6}}, |
| 228 | } |
| 229 | for i, tt := range tests { |
| 230 | tree := bt.NewAVL[int]() |
| 231 | tree.Push(tt.input...) |
| 232 | if ret := tree.LevelOrder(); !reflect.DeepEqual(ret, tt.want) { |
| 233 | t.Errorf("#%d Error with LevelOrder", i) |
| 234 | } |
| 235 | } |
| 236 | }) |
| 237 | |
| 238 | t.Run("Test for Red-Black Tree", func(t *testing.T) { |
| 239 | tests := []struct { |
| 240 | input []int |
| 241 | want []int |
| 242 | }{ |
| 243 | {[]int{90, 80, 100, 70, 85, 95, 105}, []int{90, 80, 100, 70, 85, 95, 105}}, |
| 244 | {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, |
| 245 | []int{80, 41, 90, 21, 61, 85, 100, 1, 31, 51, 70, 95, 105, 71}}, |
| 246 | {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{7, 5, 9, 3, 6, 8, 10, 2, 4, 1}}, |
| 247 | } |
| 248 | for i, tt := range tests { |
| 249 | tree := bt.NewRB[int]() |
| 250 | tree.Push(tt.input...) |
| 251 | if ret := tree.LevelOrder(); !reflect.DeepEqual(ret, tt.want) { |
| 252 | t.Errorf("#%d Error with LevelOrder %v", i, ret) |
| 253 | } |
| 254 | } |
| 255 | }) |
| 256 | } |
nothing calls this directly
no test coverage detected