-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
67 lines (55 loc) · 1.09 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
64
65
66
67
package PriorityQueue
import (
"github.com/magiconair/properties/assert"
"testing"
)
func TestQueuePush(t *testing.T) {
item := struct{}{}
q := Build()
q.Push(item, 2)
assert.Equal(t, q.Len(), 1)
}
func TestQueuePull(t *testing.T) {
item := struct{}{}
q := Build()
q.Push(item, 2)
gotItem, _ := q.Pull()
assert.Equal(t, gotItem, item)
}
func TestQueuePullEmpty(t *testing.T) {
q := Build()
gotItem, err := q.Pull()
assert.Equal(t, err.Error(), "empty")
assert.Equal(t, gotItem, nil)
}
func TestQueueLen(t *testing.T) {
q := Build()
assert.Equal(t, q.Len(), 0)
q.Push(struct{}{}, 1)
assert.Equal(t, q.Len(), 1)
}
func TestPriority(t *testing.T) {
item1 := 111
item2 := 222
q := Build()
q.Push(item2, 2)
q.Push(item1, 1)
gotItem, _ := q.Pull()
assert.Equal(t, gotItem, item1)
}
func TestPrioritize(t *testing.T) {
ch1 := make(chan interface{})
ch2 := make(chan interface{})
item1 := 111
item2 := 222
outCh, _ := Prioritize(ch1, ch2)
ch2 <- item2
ch2 <- item2
ch2 <- item2
ch1 <- item1
ch1 <- item1
ch1 <- item1
<-outCh
got := <-outCh
assert.Equal(t, got, item1)
}