-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriorityqueue_test.go
More file actions
57 lines (44 loc) · 1.01 KB
/
priorityqueue_test.go
File metadata and controls
57 lines (44 loc) · 1.01 KB
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
package async
import "testing"
func TestPriorityQueue(t *testing.T) {
t.Run("Overall", func(t *testing.T) {
var pq priorityqueue[*Coroutine]
for _, lv := range []uint32{1, 2, 3, 4, 5, 6, 7, 8} {
pq.Push(&Coroutine{level: lv})
}
for _, lv := range []uint32{1, 2, 3, 4} {
if co := pq.Pop(); co.level != lv {
t.FailNow()
}
}
for _, lv := range []uint32{9, 10, 11} {
pq.Push(&Coroutine{level: lv})
}
pq.Push(&Coroutine{level: 4})
if co := pq.Pop(); co.level != 4 {
t.FailNow()
}
pq.Push(&Coroutine{level: 7})
pq.Push(&Coroutine{level: 6})
for _, lv := range []uint32{5, 6, 6, 7, 7, 8, 9, 10, 11} {
if co := pq.Pop(); co.level != lv {
t.FailNow()
}
}
if !pq.Empty() {
t.FailNow()
}
})
t.Run("FIFO", func(t *testing.T) {
var pq priorityqueue[*Coroutine]
co1 := new(Coroutine)
co2 := new(Coroutine)
co3 := new(Coroutine)
pq.Push(co1)
pq.Push(co2)
pq.Push(co3)
if pq.Pop() != co1 || pq.Pop() != co2 || pq.Pop() != co3 {
t.FailNow()
}
})
}