forked from digisan/go-generics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_test.go
58 lines (51 loc) · 1.08 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
package gogenerics
import (
"fmt"
"testing"
)
func TestPush(t *testing.T) {
s := Stack[string](dataStr)
n := s.Push("e", "f", "g")
fmt.Println(n)
fmt.Println(s, s.Len())
}
func TestPop(t *testing.T) {
s := Stack[string](dataStr)
s.Push("e", "f", "g")
fmt.Println(s, s.Len())
n := s.Len()
for i := 0; i <= n; i++ {
ele, ok := s.Pop()
fmt.Println(ele, ok, "left:", s.Len())
}
}
func TestStackPeek(t *testing.T) {
s := Stack[int](dataInt)
n := s.Len()
for i := 0; i <= n; i++ {
ele, ok := s.Peek()
fmt.Println(ele, ok, "left:", s.Len())
}
}
func TestStackClear(t *testing.T) {
s := Stack[int](dataInt)
fmt.Println("s:", s, s.Len())
o := s.Clear()
fmt.Println("ori:", o, o.Len())
fmt.Println("after clear, s:", s, s.Len())
}
func TestStackCopy(t *testing.T) {
s := Stack[int](dataInt)
fmt.Println("s:", s, s.Len())
cp := s.Copy()
s.Clear()
fmt.Println("after clear, s:", s, s.Len())
fmt.Println("cp", cp, cp.Len())
}
func TestStackSink(t *testing.T) {
s := Stack[string](dataStr)
fmt.Println("s:", s, s.Len())
for _, e := range s.Sink() {
fmt.Println(e)
}
}