-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
422 lines (339 loc) · 21.5 KB
/
stack_test.go
File metadata and controls
422 lines (339 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
package stack_test
import (
"fmt"
"testing"
"github.com/blorticus-go/stack"
"github.com/onsi/gomega"
. "github.com/onsi/gomega"
)
func TestNonConcurrentNonCircularStackWithoutMax(t *testing.T) {
g := NewGomegaWithT(t)
s := stack.NewStackWithInitialSizeHint(4)
for _, testCase := range []*stackOperationTestCase{
{testname: "New Clear Stack Initial Check", operation: "check", expectedStackDepthAfterOperation: 0},
{testname: "New Clear Stack Pop", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Push first value", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push second value", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push third value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Pop with first three values", operation: "pop", expectedPopValue: "third", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Push fourth value", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "First pop after fourth push", operation: "pop", expectedPopValue: "fourth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Second pop after fourth push", operation: "pop", expectedPopValue: "second", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Push fifth value", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push sixth value", operation: "push", valueToPush: "sixth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Push seventh value", operation: "push", valueToPush: "seventh", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 4},
{testname: "Push eighth", operation: "push", valueToPush: "eighth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 5},
{testname: "Push ninth value", operation: "push", valueToPush: "ninth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 6},
{testname: "First pop after ninth push", operation: "pop", expectedPopValue: "ninth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 5},
{testname: "Second pop after ninth push", operation: "pop", expectedPopValue: "eighth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 4},
{testname: "Third pop after ninth push", operation: "pop", expectedPopValue: "seventh", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 3},
{testname: "Fourth pop after ninth push", operation: "pop", expectedPopValue: "sixth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Fifth pop after ninth push", operation: "pop", expectedPopValue: "fifth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Sixth pop after ninth push", operation: "pop", expectedPopValue: "first", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 0},
{testname: "Seventh pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Eighth pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
} {
testCase.evaluateAgainstStack(s, g)
}
}
func TestNonConcurrentNonCircularStackWithMax(t *testing.T) {
g := NewGomegaWithT(t)
s := stack.NewStack().WithAMaximumDepthOf(4)
for _, testCase := range []*stackOperationTestCase{
{testname: "New Clear Stack Initial Check", operation: "check", expectedStackDepthAfterOperation: 0},
{testname: "New Clear Stack Pop", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Push first value", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push second value", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push third value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Pop with first three values", operation: "pop", expectedPopValue: "third", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Push fourth value", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "First pop after fourth push", operation: "pop", expectedPopValue: "fourth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Second pop after fourth push", operation: "pop", expectedPopValue: "second", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Push fifth value", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push sixth value", operation: "push", valueToPush: "sixth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Push seventh value", operation: "push", valueToPush: "seventh", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 4},
{testname: "Push eighth", operation: "push", valueToPush: "eighth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 4},
{testname: "Push ninth value", operation: "push", valueToPush: "ninth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 4},
{testname: "First pop after ninth push", operation: "pop", expectedPopValue: "seventh", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 3},
{testname: "Second pop after ninth push", operation: "pop", expectedPopValue: "sixth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Third pop after ninth push", operation: "pop", expectedPopValue: "fifth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Fourth pop after ninth push", operation: "pop", expectedPopValue: "first", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 0},
{testname: "Seventh pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Eighth pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
} {
testCase.evaluateAgainstStack(s, g)
}
}
func TestNonConcurrentRoundedDiscardingStack(t *testing.T) {
g := NewGomegaWithT(t)
s := stack.NewBoundedDiscardingStack(4)
for _, testCase := range []*stackOperationTestCase{
{testname: "New Clear Stack Initial Check", operation: "check", expectedStackDepthAfterOperation: 0},
{testname: "New Clear Stack Pop", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Push first value", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push second value", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push third value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Pop with first three values", operation: "pop", expectedPopValue: "third", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Push fourth value", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "First pop after fourth push", operation: "pop", expectedPopValue: "fourth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Second pop after fourth push", operation: "pop", expectedPopValue: "second", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Push fifth value", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push sixth value", operation: "push", valueToPush: "sixth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Push seventh value", operation: "push", valueToPush: "seventh", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 4},
{testname: "Push eighth", operation: "push", valueToPush: "eighth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 4},
{testname: "Push ninth value", operation: "push", valueToPush: "ninth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 4},
{testname: "First pop after ninth push", operation: "pop", expectedPopValue: "ninth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 3},
{testname: "Second pop after ninth push", operation: "pop", expectedPopValue: "eighth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Third pop after ninth push", operation: "pop", expectedPopValue: "seventh", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Fourth pop after ninth push", operation: "pop", expectedPopValue: "sixth", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 0},
{testname: "Seventh pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
{testname: "Eighth pop after ninth push", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
} {
testCase.evaluateAgainstStack(s, g)
}
s = stack.NewBoundedDiscardingStack(150)
// the code arbitrarily uses 100 as the append cutoff for discarding stacks
for i := 0; i < 149; i++ {
if stackWasAlreadyFull := s.Push("v"); stackWasAlreadyFull {
t.Fatalf("[Discarding Stack with 150 Depth] On push %d received stackWasAlreadyFull, expected stack to not be full", i)
}
}
if stackWasAlreadyFull := s.Push("v"); !stackWasAlreadyFull {
t.Fatalf("[Discarding Stack with 150 Depth] On push 150 received !stackWasAlreadyFull, expected stack to be full")
}
for i := 0; i < 150; i++ {
if _, stackWasAlreadyEmpty := s.Pop(); stackWasAlreadyEmpty {
t.Fatalf("[Discarding Stack with 150 Depth] On pop %d received stackWasAlreadyEmpty, expected stack to not be already empty", i)
}
}
if _, stackWasAlreadyEmpty := s.Pop(); !stackWasAlreadyEmpty {
t.Fatalf("[Discarding Stack with 150 Depth] On pop 151 received !stackWasAlreadyEmpty, expected stack to be already empty")
}
}
func TestReset(t *testing.T) {
g := NewGomegaWithT(t)
s := stack.NewStack()
for _, testCase := range []*stackOperationTestCase{
{testname: "New Clear Stack Initial Check", operation: "check", expectedStackDepthAfterOperation: 0},
{testname: "Reset of Empty Stack", operation: "reset", expectedStackDepthAfterOperation: 0},
{testname: "Push First Value", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push second value", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push third value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Reset of Stack With Three Values", operation: "reset", expectedStackDepthAfterOperation: 0},
{testname: "Push Third Value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push Fourth value", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push Fifth value", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
} {
testCase.evaluateAgainstStack(s, g)
}
}
func testForPanic(functionThatShouldPanic func()) (functionDidPanic bool) {
c := make(chan bool)
go func(c chan bool, f func()) {
defer func() {
err := recover()
if err != nil {
c <- true
}
}()
functionThatShouldPanic()
c <- false
}(c, functionThatShouldPanic)
return <-c
}
func TestMaximumResizeSmaller(t *testing.T) {
g := NewGomegaWithT(t)
s := stack.NewStack().WithAMaximumDepthOf(6)
for _, testCase := range []*stackOperationTestCase{
{testname: "Push First Value", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push Second value", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push Third value", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Push Fourth value", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 4},
{testname: "Push Fifth value", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 5},
{testname: "Push Sixth value", operation: "push", valueToPush: "sixth", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 6},
} {
testCase.evaluateAgainstStack(s, g)
}
s.SetMaximumDepthTo(3)
for _, testCase := range []*stackOperationTestCase{
{testname: "First Pop After Resize", operation: "pop", expectedPopValue: "third", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 2},
{testname: "Second Pop After Resize", operation: "pop", expectedPopValue: "second", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 1},
{testname: "Third Pop After Resize", operation: "pop", expectedPopValue: "first", expectStackToHaveBeenEmpty: false, expectedStackDepthAfterOperation: 0},
{testname: "Fourth Pop After Resize", operation: "pop", expectStackToHaveBeenEmpty: true, expectedStackDepthAfterOperation: 0},
} {
testCase.evaluateAgainstStack(s, g)
}
for _, testCase := range []*stackOperationTestCase{
{testname: "Push First Value after resize", operation: "push", valueToPush: "first", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 1},
{testname: "Push Second value after resize", operation: "push", valueToPush: "second", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 2},
{testname: "Push Third value after resize", operation: "push", valueToPush: "third", expectStackToHaveBeenFull: false, expectedStackDepthAfterOperation: 3},
{testname: "Push Fourth value after resize", operation: "push", valueToPush: "fourth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 3},
{testname: "Push Fifth value after resize", operation: "push", valueToPush: "fifth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 3},
{testname: "Push Sixth value after resize", operation: "push", valueToPush: "sixth", expectStackToHaveBeenFull: true, expectedStackDepthAfterOperation: 3},
} {
testCase.evaluateAgainstStack(s, g)
}
}
func TestPanicConditions(t *testing.T) {
f := func() { stack.NewStack().WithAMaximumDepthOf(0) }
if functionDidPanic := testForPanic(f); !functionDidPanic {
t.Errorf("On NewStack WithMaximumDepthOf 0 expected panic, did not panic")
}
f = func() { stack.NewBoundedDiscardingStack(5).WithAMaximumDepthOf(10) }
if functionDidPanic := testForPanic(f); !functionDidPanic {
t.Errorf("On attempt to set MaximumDepth on DiscardingStack expected panic, did not panic")
}
}
type typedPopTestCase struct {
testname string
expectedValue interface{}
expectStackToHaveBeenEmpty bool
}
type conversionAttemptMessage struct {
msgType string // "success", "does not match", "stack is empty", "panic"
panicError error
}
func (testCase *typedPopTestCase) attemptTypeConvertedPop(s *stack.Stack, conversionAttemptMessageChannel chan *conversionAttemptMessage) {
defer func(c chan *conversionAttemptMessage) {
if err := recover(); err != nil {
c <- &conversionAttemptMessage{
msgType: "panic",
panicError: err.(error),
}
}
}(conversionAttemptMessageChannel)
switch testCase.expectedValue.(type) {
case int:
v, stackIsEmpty := s.PopInt()
if stackIsEmpty {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "stack is empty"}
return
}
if v != testCase.expectedValue.(int) {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "does not match"}
return
}
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "success"}
return
case uint:
v, stackIsEmpty := s.PopUint()
if stackIsEmpty {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "stack is empty"}
return
}
if v != testCase.expectedValue.(uint) {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "does not match"}
return
}
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "success"}
return
case string:
v, stackIsEmpty := s.PopString()
if stackIsEmpty {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "stack is empty"}
return
}
if v != testCase.expectedValue.(string) {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "does not match"}
return
}
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "success"}
return
case byte:
v, stackIsEmpty := s.PopByte()
if stackIsEmpty {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "stack is empty"}
return
}
if v != testCase.expectedValue.(byte) {
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "does not match"}
return
}
conversionAttemptMessageChannel <- &conversionAttemptMessage{msgType: "success"}
return
}
}
func (testCase *typedPopTestCase) evaulateAgainstStack(s *stack.Stack) error {
conversionAttemptMessageChannel := make(chan *conversionAttemptMessage)
go testCase.attemptTypeConvertedPop(s, conversionAttemptMessageChannel)
msg := <-conversionAttemptMessageChannel
switch msg.msgType {
case "success":
return nil
case "does not match":
return fmt.Errorf("popped value does not match expected value")
case "stack is empty":
if !testCase.expectStackToHaveBeenEmpty {
return fmt.Errorf("stack was empty before pop but that was not expected")
}
return nil
case "panic":
return fmt.Errorf("a panic occurred: %s", msg.panicError.Error())
}
return fmt.Errorf("an unexpected condition was returned")
}
func TestTypedPopping(t *testing.T) {
s := stack.NewStack()
for i, v := range []interface{}{
"string",
uint(10),
int(-10),
byte(100),
} {
if stackWasAlreadyFull := s.Push(v); stackWasAlreadyFull {
t.Errorf("On push %d expected stack to not be full but was", i+1)
}
}
for _, testCase := range []*typedPopTestCase{
{"pop of byte 100", byte(100), false},
{"pop of int -10", int(-10), false},
{"pop of uint 10", uint(10), false},
{"pop of string 'string'", "string", false},
{testname: "pop int when stack is empty", expectedValue: int(0), expectStackToHaveBeenEmpty: true},
{testname: "pop uint when stack is empty", expectedValue: uint(0), expectStackToHaveBeenEmpty: true},
{testname: "pop string when stack is empty", expectedValue: "", expectStackToHaveBeenEmpty: true},
{testname: "pop byte when stack is empty", expectedValue: byte(0), expectStackToHaveBeenEmpty: true},
} {
if err := testCase.evaulateAgainstStack(s); err != nil {
t.Errorf("[%s] %s", testCase.testname, err.Error())
}
}
}
type stackOperationTestCase struct {
testname string
operation string // "push", "pop", "check", "reset"
valueToPush string
expectedPopValue string
expectStackToHaveBeenEmpty bool
expectStackToHaveBeenFull bool
expectedStackDepthAfterOperation uint
}
func (testCase *stackOperationTestCase) evaluateAgainstStack(s *stack.Stack, g *gomega.WithT) {
switch testCase.operation {
case "push":
stackWasAlreadyFull := s.Push(testCase.valueToPush)
if testCase.expectStackToHaveBeenFull {
g.Expect(stackWasAlreadyFull).To(BeTrue(), fmt.Sprintf("[%s] stack should have been full on push", testCase.testname))
} else {
g.Expect(stackWasAlreadyFull).To(BeFalse(), fmt.Sprintf("[%s] stack should have been full on push", testCase.testname))
}
case "pop":
poppedValue, stackWasAlreadyEmpty := s.Pop()
if testCase.expectStackToHaveBeenEmpty {
g.Expect(stackWasAlreadyEmpty).To(BeTrue(), fmt.Sprintf("[%s] stack should be empty on pop", testCase.testname))
} else {
g.Expect(stackWasAlreadyEmpty).To(BeFalse(), fmt.Sprintf("[%s] stack should be empty on pop", testCase.testname))
g.Expect(poppedValue.(string)).To(Equal(testCase.expectedPopValue), fmt.Sprintf("[%s] popped value should be", testCase.expectedPopValue))
}
case "reset":
s.ResetToEmpty()
}
if s.Depth() != testCase.expectedStackDepthAfterOperation {
g.Expect(s.Depth()).To(Equal(testCase.expectedStackDepthAfterOperation), fmt.Sprintf("[%s] after %s stack depth should be %d", testCase.testname, testCase.operation, testCase.expectedStackDepthAfterOperation))
}
if testCase.expectedStackDepthAfterOperation == 0 {
g.Expect(s.IsEmpty()).To(BeTrue(), fmt.Sprintf("[%s] stack IsEmpty should be true", testCase.testname))
} else {
g.Expect(s.IsEmpty()).To(BeFalse(), fmt.Sprintf("[%s] stack IsEmpty should be false", testCase.testname))
}
}