-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueue_test.go
More file actions
49 lines (42 loc) · 770 Bytes
/
queue_test.go
File metadata and controls
49 lines (42 loc) · 770 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
43
44
45
46
47
48
49
package queue
import (
"fmt"
"testing"
)
type mySimpler struct {
i []int
}
func (m mySimpler) Len() int {
return len(m.i)
}
func (m mySimpler) Pop(i int) interface{} {
return m.i[i]
}
func TestCountChanQueue(t *testing.T) {
s := mySimpler{i: make([]int, 100)}
q := NewQueue(s)
chCount := make(chan int)
go func(ch chan int) {
count := 0
for {
select {
// case i := <-q.Pop():
// fmt.Println("first", i)
// count++
// case i := <-q.Pop():
// fmt.Println("second", i)
// count++
case i := <-q.Pop():
fmt.Println("get", i)
count++
case <-q.Empty():
fmt.Println("quit")
ch <- count
}
}
}(chCount)
count := <-chCount
if count != 100 {
t.Error("it should return only 100 times but got", count)
}
}