34 lines
575 B
Go
34 lines
575 B
Go
|
|
package test
|
||
|
|
|
||
|
|
import "math"
|
||
|
|
import "math/bits"
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
import "github.com/firestuff/subcoding/gen"
|
||
|
|
|
||
|
|
func TestRandBiasedUint64(t *testing.T) {
|
||
|
|
buckets := [65]uint64{}
|
||
|
|
|
||
|
|
for i := 0; i < 1000000; i++ {
|
||
|
|
val := gen.RandBiasedUint64()
|
||
|
|
buckets[bits.Len64(val)]++
|
||
|
|
}
|
||
|
|
|
||
|
|
var max uint64 = 0
|
||
|
|
var min uint64 = math.MaxUint64
|
||
|
|
|
||
|
|
for _, count := range buckets {
|
||
|
|
if count > max {
|
||
|
|
max = count
|
||
|
|
}
|
||
|
|
|
||
|
|
if count < min {
|
||
|
|
min = count
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if max - min > max / 10 {
|
||
|
|
t.Fatalf("Variance greater than allowed: %d > %d (max=%d min=%d)", max - min, max / 10, max, min)
|
||
|
|
}
|
||
|
|
}
|