forked from digisan/go-generics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_test.go
63 lines (55 loc) · 1.17 KB
/
queue_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
package gogenerics
import (
"fmt"
"testing"
)
var (
dataStr = []string{"a", "b", "c", "d"}
dataInt = []int{1, 2, 3, 4, 5}
)
func TestEnqueue(t *testing.T) {
q := Queue[string](dataStr)
n := q.Enqueue("e", "f", "g")
fmt.Println(n)
fmt.Println(q, q.Len())
}
func TestDequeue(t *testing.T) {
q := Queue[string](dataStr)
q.Enqueue("e", "f", "g")
fmt.Println(q, q.Len())
n := q.Len()
for i := 0; i <= n; i++ {
ele, ok := q.Dequeue()
fmt.Println(ele, ok, "left:", q.Len())
}
}
func TestQueuePeek(t *testing.T) {
q := Queue[int](dataInt)
n := q.Len()
for i := 0; i <= n; i++ {
ele, ok := q.Peek()
fmt.Println(ele, ok, "left:", q.Len())
}
}
func TestQueueClear(t *testing.T) {
q := Queue[int](dataInt)
fmt.Println("q:", q, q.Len())
o := q.Clear()
fmt.Println("ori:", o, o.Len())
fmt.Println("after clear, q:", q, q.Len())
}
func TestQueueCopy(t *testing.T) {
q := Queue[int](dataInt)
fmt.Println("q:", q, q.Len())
cp := q.Copy()
q.Clear()
fmt.Println("after clear, q:", q, q.Len())
fmt.Println("cp:", cp, cp.Len())
}
func TestQueueSink(t *testing.T) {
q := Queue[string](dataStr)
fmt.Println("q:", q, q.Len())
for _, e := range q.Sink() {
fmt.Println(e)
}
}