Skip to content

Commit

Permalink
Tests: backport go1.6 rand.Read for speedup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost committed Apr 7, 2016
1 parent 58c5128 commit 9f0bea8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 7 additions & 3 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import (
"github.com/klauspost/reedsolomon"
)

func fillRandom(b []byte) {
for i := range b {
b[i] = byte(rand.Int() & 0xff)
func fillRandom(p []byte) {
for i := 0; i < len(p); i += 7 {
val := rand.Int63()
for j := 0; i+j < len(p) && j < 7; j++ {
p[i+j] = byte(val)
val >>= 8
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions reedsolomon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ func TestOneEncode(t *testing.T) {

}

func fillRandom(b []byte) {
for i := range b {
b[i] = byte(rand.Int() & 0xff)
func fillRandom(p []byte) {
for i := 0; i < len(p); i += 7 {
val := rand.Int63()
for j := 0; i+j < len(p) && j < 7; j++ {
p[i+j] = byte(val)
val >>= 8
}
}
}

Expand Down
8 changes: 2 additions & 6 deletions streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,15 @@ func TestStreamEncodingConcurrent(t *testing.T) {

func randomBuffer(length int) *bytes.Buffer {
b := make([]byte, length)
for i := range b {
b[i] = byte(rand.Int() & 0xff)
}
fillRandom(b)
return bytes.NewBuffer(b)
}

func randomBytes(n, length int) [][]byte {
bufs := make([][]byte, n)
for j := range bufs {
bufs[j] = make([]byte, length)
for i := range bufs[j] {
bufs[j][i] = byte(rand.Int() & 0xff)
}
fillRandom(bufs[j])
}
return bufs
}
Expand Down

0 comments on commit 9f0bea8

Please sign in to comment.