-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathstack_test.go
More file actions
42 lines (35 loc) · 760 Bytes
/
stack_test.go
File metadata and controls
42 lines (35 loc) · 760 Bytes
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
package stack_test
import (
"fmt"
"testing"
"github.com/zyedidia/generic/stack"
)
func assert(t *testing.T, fn func() bool) {
if !fn() {
t.Fatal("assert failed")
}
}
func TestSimple(t *testing.T) {
st := stack.New[int]()
st.Push(0)
assert(t, func() bool { return st.Peek() == 0 })
st.Push(42)
assert(t, func() bool { return st.Pop() == 42 })
assert(t, func() bool { return st.Pop() == 0 })
assert(t, func() bool { return st.Size() == 0 })
assert(t, func() bool { return st.Pop() == 0 })
assert(t, func() bool { return st.Peek() == 0 })
}
func Example() {
st := stack.New[string]()
st.Push("foo")
st.Push("bar")
fmt.Println(st.Pop())
fmt.Println(st.Peek())
st.Push("baz")
fmt.Println(st.Size())
// Output:
// bar
// foo
// 2
}