1
0
mirror of https://github.com/golang/go synced 2024-11-22 09:44:40 -07:00

crypto/rand: improve TestReadLoops

As suggested by Russ Cox, making sure we see all byte values doesn't
take long and is a superset of the existing test.

Change-Id: Ifc7f18ca4189c89a3d06d0408150a2464ce5e590
Reviewed-on: https://go-review.googlesource.com/c/go/+/608397
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Filippo Valsorda 2024-08-26 17:53:46 +02:00
parent ef14ba3e68
commit 55b930eb07

View File

@ -49,27 +49,20 @@ func testRead(t *testing.T, Read func([]byte) (int, error)) {
}
}
func TestReadLoops(t *testing.T) {
testReadAndReader(t, testReadLoops)
func TestReadByteValues(t *testing.T) {
testReadAndReader(t, testReadByteValues)
}
func testReadLoops(t *testing.T, Read func([]byte) (int, error)) {
func testReadByteValues(t *testing.T, Read func([]byte) (int, error)) {
b := make([]byte, 1)
v := make(map[byte]bool)
for {
n, err := Read(b)
if n != 1 || err != nil {
t.Fatalf("Read(b) = %d, %v", n, err)
}
if b[0] == 42 {
break
}
}
for {
n, err := Read(b)
if n != 1 || err != nil {
t.Fatalf("Read(b) = %d, %v", n, err)
}
if b[0] == 0 {
v[b[0]] = true
if len(v) == 256 {
break
}
}