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

Function TestRB

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

Source from the content-addressed store, hash-verified

126}
127
128func TestRB(t *testing.T) {
129 tree = bt.NewRB[int]()
130
131 if tree.Empty() {
132 t.Log("RB Tree is empty now.")
133 }
134
135 tree.Push(1, 4, 10)
136 tree.Push(-8)
137 nums := []int{87, 18, 10, -34}
138 tree.Push(nums...)
139 tree.Push(4) // duplicate key, dismiss it
140
141 if tree.Has(4) {
142 t.Logf("There is a node of 4")
143 }
144
145 if n, ok := tree.Get(10); ok {
146 t.Logf("node of 10: %T", n)
147 }
148
149 if ret, ok := tree.Min(); ok {
150 t.Logf("tree.Min() = %v", ret)
151 }
152
153 if ret, ok := tree.Max(); ok {
154 t.Logf("tree.Max() = %v", ret)
155 }
156
157 if ret, ok := tree.Predecessor(1); ok {
158 t.Logf("tree.Preducessor(1) = %v", ret)
159 }
160
161 if ret, ok := tree.Successor(18); ok {
162 t.Logf("tree.Successor(18) = %v", ret)
163 }
164
165 fmt.Println(tree.InOrder())
166 fmt.Println(tree.AccessNodesByLayer())
167}

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected