-
Notifications
You must be signed in to change notification settings - Fork 0
/
priorityqueue_test.go
57 lines (44 loc) · 1002 Bytes
/
priorityqueue_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
package async
import "testing"
func TestPriorityQueue(t *testing.T) {
t.Run("Overall", func(t *testing.T) {
var pq priorityqueue[*Coroutine]
for _, r := range "abcdefgh" {
pq.Push(&Coroutine{path: string(r)})
}
for _, r := range "abcd" {
if co := pq.Pop(); co.path != string(r) {
t.FailNow()
}
}
for _, r := range "ijk" {
pq.Push(&Coroutine{path: string(r)})
}
pq.Push(&Coroutine{path: "d"})
if co := pq.Pop(); co.path != "d" {
t.FailNow()
}
pq.Push(&Coroutine{path: "g"})
pq.Push(&Coroutine{path: "f"})
for _, r := range "effgghijk" {
if co := pq.Pop(); co.path != string(r) {
t.FailNow()
}
}
if !pq.Empty() {
t.FailNow()
}
})
t.Run("FIFO", func(t *testing.T) {
var pq priorityqueue[*Coroutine]
co1 := &Coroutine{path: "/"}
co2 := &Coroutine{path: "/"}
co3 := &Coroutine{path: "/"}
pq.Push(co1)
pq.Push(co2)
pq.Push(co3)
if pq.Pop() != co1 || pq.Pop() != co2 || pq.Pop() != co3 {
t.FailNow()
}
})
}