MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestTreePostOrder

Function TestTreePostOrder

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

Source from the content-addressed store, hash-verified

138}
139
140func TestTreePostOrder(t *testing.T) {
141 t.Run("Test for Binary-Search Tree", func(t *testing.T) {
142 tests := []struct {
143 input []int
144 want []int
145 }{
146 {[]int{90, 80, 100, 70, 85, 95, 105}, []int{70, 85, 80, 95, 105, 100, 90}},
147 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71},
148 []int{61, 51, 41, 31, 21, 1, 71, 70, 85, 80, 95, 105, 100, 90}},
149 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
150 }
151 for i, tt := range tests {
152 tree := bt.NewBinarySearch[int]()
153 tree.Push(tt.input...)
154 if ret := tree.PostOrder(); !reflect.DeepEqual(ret, tt.want) {
155 t.Errorf("#%d Error with Post", i)
156 }
157 }
158 })
159
160 t.Run("Test for AVL Tree", func(t *testing.T) {
161 tests := []struct {
162 input []int
163 want []int
164 }{
165 {[]int{90, 80, 100, 70, 85, 95, 105}, []int{70, 85, 80, 95, 105, 100, 90}},
166 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71},
167 []int{1, 31, 21, 61, 51, 41, 71, 85, 80, 95, 105, 100, 90, 70}},
168 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{1, 2, 4, 6, 5, 3, 8, 10, 9, 7}},
169 }
170 for i, tt := range tests {
171 tree := bt.NewAVL[int]()
172 tree.Push(tt.input...)
173 if ret := tree.PostOrder(); !reflect.DeepEqual(ret, tt.want) {
174 t.Errorf("#%d Error with PostOrder", i)
175 }
176 }
177 })
178
179 t.Run("Test for Red-Black Tree", func(t *testing.T) {
180 tests := []struct {
181 input []int
182 want []int
183 }{
184 {[]int{90, 80, 100, 70, 85, 95, 105}, []int{70, 85, 80, 95, 105, 100, 90}},
185 {[]int{90, 80, 100, 70, 85, 95, 105, 1, 21, 31, 41, 51, 61, 71},
186 []int{1, 31, 21, 51, 71, 70, 61, 41, 85, 95, 105, 100, 90, 80}},
187 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, []int{1, 2, 4, 3, 6, 5, 8, 10, 9, 7}},
188 }
189 for i, tt := range tests {
190 tree := bt.NewRB[int]()
191 tree.Push(tt.input...)
192 if ret := tree.PostOrder(); !reflect.DeepEqual(ret, tt.want) {
193 t.Errorf("#%d Error with PostOrder", i)
194 }
195 }
196 })
197}

Callers

nothing calls this directly

Calls 2

PushMethod · 0.65
PostOrderMethod · 0.65

Tested by

no test coverage detected