github.com/xaionaro-go/rand@v0.0.0-20191005105903-aba1befc54a5/mathrand/utils_test.go (about)

     1  package mathrand_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  )
     8  
     9  func panicIfError(err error) {
    10  	if err != nil {
    11  		panic(err)
    12  	}
    13  }
    14  
    15  func prepareSample(sampleName string, readFunc func([]byte) (int, error), isXORRead bool) {
    16  	b := make([]byte, 1<<20)
    17  	_, err := readFunc(b)
    18  	panicIfError(err)
    19  	if isXORRead {
    20  		_, err := readFunc(b)
    21  		panicIfError(err)
    22  	}
    23  	err = ioutil.WriteFile(filepath.Join(os.TempDir(), "prngSample-"+sampleName+".bin"), b, 0755)
    24  	panicIfError(err)
    25  }