aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/aws-sdk-go-v2/internal/rand/rand_test.go
blob: b5d3b7da7f7bb9c1b1b26c0376527c3d7315e53e (plain) (blame)
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
package rand

import (
	"bytes"
	"io"
	"testing"
)

func TestGitterDelay(t *testing.T) {
	maxFloat1 := 1 - 1/float64(1<<53)

	cases := map[string]struct {
		Reader io.Reader
		Expect float64
	}{
		"floor": {
			Reader: bytes.NewReader([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
			Expect: 0,
		},
		"ceiling": {
			Reader: bytes.NewReader([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}),
			Expect: maxFloat1,
		},
	}

	for name, c := range cases {
		t.Run(name, func(t *testing.T) {
			d, err := Float64(c.Reader)
			if err != nil {
				t.Fatalf("expect no error, %v", err)
			}

			if e, a := c.Expect, d; e != a {
				t.Errorf("expect %v delay, got %v", e, a)
			}
		})
	}
}