MCPcopy
hub / github.com/TheAlgorithms/Go / TestRBTreeString

Function TestRBTreeString

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

Source from the content-addressed store, hash-verified

121}
122
123func TestRBTreeString(t *testing.T) {
124 tree := bt.NewRB[string]()
125
126 if tree.Has("Golang") {
127 t.Errorf("Error with Has when T is string.")
128 }
129
130 strs := []string{"Hello", "World", "Golang", "Python", "Rust", "C", "JavaScript", "Haskell", "Pascal", "ZZ"}
131 for _, str := range strs {
132 tree.Push(str)
133 }
134
135 if !tree.Has("Golang") {
136 t.Errorf("Error with Has when T is string.")
137 }
138
139 if tree.Has("Pasc") {
140 t.Errorf("Error with Has when T is string.")
141 }
142
143 if ok := tree.Delete("Hello"); !ok {
144 t.Errorf("Error with Delete when T is string.")
145 }
146
147 if ok := tree.Delete("Pasc"); ok {
148 t.Errorf("Error with Delete when T is string.")
149 }
150
151 if tree.Has("Hello") {
152 t.Errorf("Error with Has when T is string.")
153 }
154
155 ret := tree.InOrder()
156 if !sort.StringsAreSorted(ret) {
157 t.Errorf("Error with Push when T is string")
158 }
159
160 if ret, ok := tree.Min(); !ok || ret != "C" {
161 t.Errorf("Error with Min when T is string")
162 }
163
164 if ret, ok := tree.Max(); !ok || ret != "ZZ" {
165 t.Errorf("Error with Max when T is string")
166 }
167}

Callers

nothing calls this directly

Calls 6

HasMethod · 0.65
PushMethod · 0.65
DeleteMethod · 0.65
InOrderMethod · 0.65
MinMethod · 0.65
MaxMethod · 0.65

Tested by

no test coverage detected