forked from quic-go/quic-go
move the random number generator to the utils package
This commit is contained in:
32
internal/utils/rand_test.go
Normal file
32
internal/utils/rand_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Rand", func() {
|
||||
It("generates random numbers", func() {
|
||||
const (
|
||||
num = 1000
|
||||
max = 123456
|
||||
)
|
||||
|
||||
var values [num]int32
|
||||
var r Rand
|
||||
for i := 0; i < num; i++ {
|
||||
v := r.Int31n(max)
|
||||
Expect(v).To(And(
|
||||
BeNumerically(">=", 0),
|
||||
BeNumerically("<", max),
|
||||
))
|
||||
values[i] = v
|
||||
}
|
||||
|
||||
var sum uint64
|
||||
for _, n := range values {
|
||||
sum += uint64(n)
|
||||
}
|
||||
Expect(float64(sum) / num).To(BeNumerically("~", max/2, max/25))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user