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

Function TestAVL

structure/tree/example_test.go:83–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestAVL(t *testing.T) {
84 tree = bt.NewAVL[int]()
85
86 if tree.Empty() {
87 t.Log("AVL Tree is empty now.")
88 }
89
90 tree.Push(1, 4, 10)
91 tree.Push(-8)
92 nums := []int{87, 18, 10, -34}
93 tree.Push(nums...)
94 tree.Push(4) // duplicate key, dismiss it
95
96 if tree.Has(4) {
97 t.Logf("There is a node of 4")
98 }
99
100 if n, ok := tree.Get(10); ok {
101 t.Logf("node of 10: %T", n)
102 }
103
104 if ret, ok := tree.Min(); ok {
105 t.Logf("tree.Min() = %v", ret)
106 }
107
108 if ret, ok := tree.Max(); ok {
109 t.Logf("tree.Max() = %v", ret)
110 }
111
112 if ret, ok := tree.Predecessor(1); ok {
113 t.Logf("tree.Preducessor(1) = %v", ret)
114 }
115
116 if ret, ok := tree.Successor(18); ok {
117 t.Logf("tree.Successor(18) = %v", ret)
118 }
119
120 fmt.Println(tree.InOrder())
121 fmt.Println(tree.AccessNodesByLayer())
122
123 tree.Delete(18)
124 fmt.Println("Delete 18")
125 fmt.Println(tree.InOrder())
126}
127
128func TestRB(t *testing.T) {
129 tree = bt.NewRB[int]()

Callers

nothing calls this directly

Calls 11

EmptyMethod · 0.65
PushMethod · 0.65
HasMethod · 0.65
GetMethod · 0.65
MinMethod · 0.65
MaxMethod · 0.65
PredecessorMethod · 0.65
SuccessorMethod · 0.65
InOrderMethod · 0.65
AccessNodesByLayerMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected