-
Notifications
You must be signed in to change notification settings - Fork 0
/
against.go
72 lines (65 loc) · 2 KB
/
against.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
package tcommon
import (
"math/rand"
"testing"
)
func testAgainst(t *testing.T, referenceLeadingZeros, targetLeadingZeros func(uint) int) {
for i := 0; i < 256; i++ {
x := uint(rand.Uint64())
expected := referenceLeadingZeros(x)
got := targetLeadingZeros(x)
if got != expected {
t.Errorf("LeadingZeros(0x%x) = %d, expected %d", x, got, expected)
}
}
}
func testAgainst8(t *testing.T, referenceLeadingZeros8, targetLeadingZeros8 func(uint8) int) {
for i := 0; i < 256; i++ {
x := uint8(rand.Uint64())
expected := referenceLeadingZeros8(x)
got := targetLeadingZeros8(x)
if got != expected {
t.Errorf("LeadingZeros8(0x%02x) = %d, expected %d", x, got, expected)
}
}
}
func testAgainst16(t *testing.T, referenceLeadingZeros16, targetLeadingZeros16 func(uint16) int) {
for i := 0; i < 256; i++ {
x := uint16(rand.Uint64())
expected := referenceLeadingZeros16(x)
got := targetLeadingZeros16(x)
if got != expected {
t.Errorf("LeadingZeros16(0x%04x) = %d, expected %d", x, got, expected)
}
}
}
func testAgainst32(t *testing.T, referenceLeadingZeros32, targetLeadingZeros32 func(uint32) int) {
for i := 0; i < 256; i++ {
x := uint32(rand.Uint64())
expected := referenceLeadingZeros32(x)
got := targetLeadingZeros32(x)
if got != expected {
t.Errorf("LeadingZeros32(0x%08x) = %d, expected %d", x, got, expected)
}
}
}
func testAgainst64(t *testing.T, referenceLeadingZeros64, targetLeadingZeros64 func(uint64) int) {
for i := 0; i < 256; i++ {
x := rand.Uint64()
expected := referenceLeadingZeros64(x)
got := targetLeadingZeros64(x)
if got != expected {
t.Errorf("LeadingZeros64(0x%016x) = %d, expected %d", x, got, expected)
}
}
}
func testAgainstPtr(t *testing.T, referenceLeadingZerosPtr, targetLeadingZerosPtr func(uintptr) int) {
for i := 0; i < 256; i++ {
x := uintptr(rand.Uint64())
expected := referenceLeadingZerosPtr(x)
got := targetLeadingZerosPtr(x)
if got != expected {
t.Errorf("LeadingZerosPtr(0x%x) = %d, expected %d", x, got, expected)
}
}
}