File: rand_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (38 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (5)
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)
			}
		})
	}
}