forked from mdlayher/schedgroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheap_test.go
69 lines (62 loc) · 1.13 KB
/
heap_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
68
69
package schedgroup
import (
"container/heap"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func Test_tasksHeap(t *testing.T) {
newTask := func(d time.Duration) task {
return task{
// Static start time for consistency, no call function.
Deadline: time.Unix(0, 0).Add(d * time.Second),
}
}
tests := []struct {
name string
in, want []task
}{
{
name: "ordered",
in: []task{
newTask(1),
newTask(2),
newTask(3),
},
want: []task{
newTask(1),
newTask(2),
newTask(3),
},
},
{
name: "unordered",
in: []task{
newTask(3),
newTask(1),
newTask(2),
},
want: []task{
newTask(1),
newTask(2),
newTask(3),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Push and pop all tasks to verify the heap.Interface implementation.
var tasks tasks
for _, v := range tt.in {
heap.Push(&tasks, v)
}
var got []task
for tasks.Len() > 0 {
got = append(got, heap.Pop(&tasks).(task))
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Fatalf("unexpected output tasks (-want +got):\n%s", diff)
}
})
}
}