-
Notifications
You must be signed in to change notification settings - Fork 4
/
bucket_test.go
54 lines (41 loc) · 1.74 KB
/
bucket_test.go
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
package cuba
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestStackBucket(t *testing.T) {
stack := NewStack()
assert.True(t, stack.IsEmpty(), "Newly constructed stack should be empty")
stack.Push("abc")
stack.Push("def")
stack.Push("ghi")
assert.False(t, stack.IsEmpty(), "Stack should not be empty after push")
var item string
item = stack.Pop().(string)
assert.Equal(t, "ghi", item, "Stack should return items in LIFO order")
assert.False(t, stack.IsEmpty(), "Stack should not be empty before popping all items")
item = stack.Pop().(string)
assert.Equal(t, "def", item, "Stack should return items in LIFO order")
assert.False(t, stack.IsEmpty(), "Stack should not be empty before popping all items")
item = stack.Pop().(string)
assert.Equal(t, "abc", item, "Stack should return items in LIFO order")
assert.True(t, stack.IsEmpty(), "Stack should be empty after popping all items")
}
func TestQueueBucket(t *testing.T) {
queue := NewQueue()
assert.True(t, queue.IsEmpty(), "Newly constructed queue should be empty")
queue.Push("abc")
queue.Push("def")
queue.Push("ghi")
assert.False(t, queue.IsEmpty(), "Queue should not be empty after push")
var item string
item = queue.Pop().(string)
assert.Equal(t, "abc", item, "Queue should return items in FIFO order")
assert.False(t, queue.IsEmpty(), "Queue should not be empty before popping all items")
item = queue.Pop().(string)
assert.Equal(t, "def", item, "Queue should return items in FIFO order")
assert.False(t, queue.IsEmpty(), "Queue should not be empty before popping all items")
item = queue.Pop().(string)
assert.Equal(t, "ghi", item, "Queue should return items in FIFO order")
assert.True(t, queue.IsEmpty(), "Queue should be empty after popping all items")
}