-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathmempool_test.go
77 lines (63 loc) · 1.71 KB
/
mempool_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
70
71
72
73
74
75
76
77
// This file is generated from mgl32/mempool_test.go; DO NOT EDIT
// Copyright 2014 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mgl64
import (
"testing"
)
func TestBinLog(t *testing.T) {
tests := []struct {
in int
// out
val int
exact bool
}{
{-256, -1, false},
{0, -1, false},
{1, 0, true},
{2, 1, true},
{3, 1, false},
{32, 5, true},
{37, 5, false},
}
for _, test := range tests {
outV, outE := binLog(test.in)
if outV != test.val || outE != test.exact {
t.Errorf("binLog gives incorrect result for input %v. Got: (%v,%v); Expected: (%v,%v)", test.in, outV, outE, test.val, test.exact)
}
}
}
func TestGetPool(t *testing.T) {
slicePools = nil
pool := getPool(3)
if len(slicePools) != 4 || pool == nil {
t.Errorf("Couldn't get pool. Size of slice %v (should be 4)", len(slicePools))
}
slice, ok := pool.Get().([]float64)
if slice == nil || !ok || cap(slice) != 1<<3 {
t.Errorf("Slice from pool either not allocated, not ok, or of wrong cap. Got slice: %v, ok: %v, cap: %v", slice, ok, cap(slice))
}
}
func TestGrabFromPool(t *testing.T) {
slicePools = nil
slice := grabFromPool(17)
if slice == nil || len(slice) != 17 || cap(slice) != 32 {
t.Errorf("Got bad, ill sized, or badly capped slice from grabFromPool. Slice: %v, len: %v, cap: %v", slice, len(slice), cap(slice))
}
}
func BenchmarkBinLogReasonable(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _ = binLog(100)
}
}
func BenchmarkBinLogBig(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _ = binLog(1<<30 + 1)
}
}
func BenchmarkBinLogSmall(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _ = binLog(10)
}
}