-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoverflow_test.go
47 lines (37 loc) · 1007 Bytes
/
overflow_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
// Copyright (c) 2024 Robert Clausecker <[email protected]>
package pospop
import "testing"
// Check if we can get the accumulators to overflow
func TestOverflow(t *testing.T) {
for i := range count64funcs {
t.Run(count64funcs[i].name, func(tt *testing.T) {
if !count64funcs[i].available {
tt.SkipNow()
}
testOverflow(tt, count64funcs[i].count64)
})
}
}
func testOverflow(t *testing.T, count64 func(*[64]int, []uint64)) {
const imax = 16
const jmax = 16
var buf [imax*65536 + jmax]uint64
for i := range buf {
buf[i] = ^uint64(0)
}
for i := 1; i <= imax; i++ {
for j := -jmax; j <= jmax; j++ {
testOverflowBuf(t, count64, buf[:i * 65536 + j])
}
}
}
func testOverflowBuf(t *testing.T, count64 func(*[64]int, []uint64), buf []uint64) {
var counts, refCounts [64]int
for i := range refCounts {
refCounts[i] = len(buf)
}
count64(&counts, buf)
if counts != refCounts {
t.Errorf("length %d: counts don't match: %v", len(buf), countDiff(counts[:], refCounts[:]))
}
}