File: rand_test.go

package info (click to toggle)
golang-github-lucas-clemente-quic-go 0.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,312 kB
  • sloc: sh: 54; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (2)
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
package utils

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestRandomNumbers(t *testing.T) {
	const (
		num = 1000
		max = 12345678
	)

	var values [num]int32
	var r Rand
	for i := 0; i < num; i++ {
		v := r.Int31n(max)
		require.GreaterOrEqual(t, v, int32(0))
		require.Less(t, v, int32(max))
		values[i] = v
	}

	var sum uint64
	for _, n := range values {
		sum += uint64(n)
	}
	average := float64(sum) / num
	expectedAverage := float64(max) / 2
	tolerance := float64(max) / 25
	require.InDelta(t, expectedAverage, average, tolerance)
}