MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestTreeDepth

Function TestTreeDepth

structure/tree/tree_test.go:295–352  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

293}
294
295func TestTreeDepth(t *testing.T) {
296 t.Run("Test for Binary-Search Tree", func(t *testing.T) {
297 tests := []struct {
298 input []int
299 want int
300 }{
301 {[]int{}, 0},
302 {[]int{90, 80, 100, 70, 85, 95, 105}, 3},
303 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, 9},
304 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 10},
305 }
306 for _, tt := range tests {
307 tree := bt.NewBinarySearch[int]()
308 tree.Push(tt.input...)
309 if ret := tree.Depth(); ret != tt.want {
310 t.Errorf("Error with Depth")
311 }
312 }
313 })
314
315 t.Run("Test for AVL Tree", func(t *testing.T) {
316 tests := []struct {
317 input []int
318 want int
319 }{
320 {[]int{}, 0},
321 {[]int{90, 80, 100, 70, 85, 95, 105}, 3},
322 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, 4},
323 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 4},
324 }
325 for i, tt := range tests {
326 tree := bt.NewAVL[int]()
327 tree.Push(tt.input...)
328 if ret := tree.Depth(); ret != tt.want {
329 t.Errorf("#%d Error with Depth", i)
330 }
331 }
332 })
333
334 t.Run("Test for Red-Black Tree", func(t *testing.T) {
335 tests := []struct {
336 input []int
337 want int
338 }{
339 {[]int{}, 0},
340 {[]int{90, 80, 100, 70, 85, 95, 105}, 3},
341 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71}, 5},
342 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 5},
343 }
344 for i, tt := range tests {
345 tree := bt.NewRB[int]()
346 tree.Push(tt.input...)
347 if ret := tree.Depth(); ret != tt.want {
348 t.Errorf("#%d Error with Depth", i)
349 }
350 }
351 })
352}

Callers

nothing calls this directly

Calls 2

PushMethod · 0.65
DepthMethod · 0.65

Tested by

no test coverage detected