-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmin_heap_node_test.go
More file actions
64 lines (56 loc) · 1.34 KB
/
Copy pathmin_heap_node_test.go
File metadata and controls
64 lines (56 loc) · 1.34 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
58
59
60
61
62
63
64
// Copyright 2020-2024 guonaihong, antlabs. All rights reserved.
//
// mit license
package timer
import (
"container/heap"
"testing"
"time"
)
func Test_NodeSizeof(t *testing.T) {
t.Run("输出最小堆node的sizeof", func(t *testing.T) {
// t.Logf("minHeapNode size: %d, %d\n", unsafe.Sizeof(minHeapNode{}), unsafe.Sizeof(time.Timer{}))
})
}
func Test_MinHeap(t *testing.T) {
t.Run("", func(t *testing.T) {
var mh minHeaps
now := time.Now()
n1 := minHeapNode{
absExpire: now.Add(time.Second),
userExpire: 1 * time.Second,
}
n2 := minHeapNode{
absExpire: now.Add(2 * time.Second),
userExpire: 2 * time.Second,
}
n3 := minHeapNode{
absExpire: now.Add(3 * time.Second),
userExpire: 3 * time.Second,
}
n6 := minHeapNode{
absExpire: now.Add(6 * time.Second),
userExpire: 6 * time.Second,
}
n5 := minHeapNode{
absExpire: now.Add(5 * time.Second),
userExpire: 5 * time.Second,
}
n4 := minHeapNode{
absExpire: now.Add(4 * time.Second),
userExpire: 4 * time.Second,
}
mh.Push(&n1)
mh.Push(&n2)
mh.Push(&n3)
mh.Push(&n6)
mh.Push(&n5)
mh.Push(&n4)
for i := 1; len(mh) > 0; i++ {
v := heap.Pop(&mh).(*minHeapNode)
if v.userExpire != time.Duration(i)*time.Second {
t.Errorf("index(%d) v.userExpire(%v) != %v", i, v.userExpire, time.Duration(i)*time.Second)
}
}
})
}