forked from oleiade/lane
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack_test.go
138 lines (115 loc) · 2.43 KB
/
stack_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
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
package lane
import (
"strconv"
"testing"
)
func TestStackPush(t *testing.T) {
stack := NewStack()
stackSize := 100
// Fulfill the test Stack
for i := 0; i < stackSize; i++ {
var value string = strconv.Itoa(i)
stack.Push(value)
}
assert(
t,
stack.container.Len() == stackSize,
"stack.container.Len() = %d; want %d", stack.container.Len(), stackSize,
)
assert(
t,
stack.container.Front().Value == "99",
"stack.container.Front().Value = %s; want %s", stack.container.Front().Value, "99",
)
assert(
t,
stack.container.Back().Value == "0",
"stack.container.Back().Value = %s; want %s", stack.container.Back().Value, "0",
)
}
func TestStackPop_fulfilled(t *testing.T) {
stack := NewStack()
stackSize := 100
// Add elements to the test Stack
for i := 0; i < stackSize; i++ {
var value string = strconv.Itoa(i)
stack.Push(value)
}
// Pop elements and assert they come out in LIFO order
for i := 99; i >= 0; i-- {
var expectedValue string = strconv.Itoa(i)
item := stack.Pop()
assert(
t,
item == expectedValue,
"stack.Pop() = %v; want %v", item, expectedValue,
)
assert(
t,
stack.container.Len() == i,
"stack.container.Len() = %d; want %d", stack.container.Len(), i,
)
}
}
func TestStackPop_empty(t *testing.T) {
stack := NewStack()
item := stack.Pop()
assert(
t,
item == nil,
"stack.Pop() = %v; want %v", item, nil,
)
assert(
t,
stack.container.Len() == 0,
"stack.container.Len() = %d; want %d", stack.container.Len(), 0,
)
}
func TestStackHead_fulfilled(t *testing.T) {
stack := NewStack()
stack.Push("1")
stack.Push("2")
stack.Push("3")
item := stack.Head()
assert(
t,
item == "3",
"stack.Head() = %v; want %v", item, "3",
)
assert(
t,
stack.container.Len() == 3,
"stack.container.Len() = %d; want %d", stack.container.Len(), 3,
)
}
func TestStackHead_empty(t *testing.T) {
stack := NewStack()
item := stack.Head()
assert(
t,
item == nil,
"stack.Head() = %v; want %v", item, nil,
)
assert(
t,
stack.container.Len() == 0,
"stack.container.Len() = %d; want %d", stack.container.Len(), 0,
)
}
func TestStackEmpty_fulfilled(t *testing.T) {
stack := NewStack()
stack.Push("1")
assert(
t,
stack.Empty() == false,
"stack.Empty() = %b; want %b", stack.Empty(), false,
)
}
func TestStackEmpty_empty_queue(t *testing.T) {
stack := NewStack()
assert(
t,
stack.Empty() == true,
"stack.Empty() = %b; want %b", stack.Empty(), true,
)
}