-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheapbench_test.go
More file actions
41 lines (39 loc) · 837 Bytes
/
heapbench_test.go
File metadata and controls
41 lines (39 loc) · 837 Bytes
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
package main
import (
"testing"
"unsafe" // for unsafe.Sizeof
)
func TestAddLiveMem(t *testing.T) {
tests := []struct {
createNodes int
wantNodes int
wantSliceLen int
}{
{1, 1, 1},
{9, 9, 1},
{10, 10, 1},
{11, 11, 2},
{99, 99, 10},
{1001, 1001, 101},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
var liveMem liveMemory
liveMem.add(memBytes(tt.createNodes * int(unsafe.Sizeof(node{}))))
gotNodes := 0
for i := range liveMem.nodes {
curr := liveMem.nodes[i]
for curr != nil {
gotNodes++
curr = curr.next
}
}
if gotNodes != tt.wantNodes {
t.Errorf("got %d nodes, want %d", gotNodes, tt.wantNodes)
}
if len(liveMem.nodes) != tt.wantSliceLen {
t.Errorf("len(liveMem.nodes) = %d, want %d", len(liveMem.nodes), tt.wantSliceLen)
}
})
}
}