-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_test.go
58 lines (50 loc) · 1 KB
/
reader_test.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gopherng_test
import (
"bytes"
_ "embed"
"fmt"
"io"
"testing"
"github.com/ethanent/gopherng/v2"
)
//go:embed testdata/seed0_out.bin
var seed0out []byte
//go:embed testdata/seed1_out.bin
var seed1out []byte
func ExampleReader() {
// Create PseudorandomReader with a seed. Use a high entropy seed in most
// real use cases.
r := gopherng.NewReader([]byte{1, 2, 3, 4, 5})
p := make([]byte, 256)
_, err := r.Read(p)
if err != nil {
/* ... */
}
fmt.Println(p)
// => [43 98 21 80 122 33 48 91 135 248 242 ... ]
}
func TestPseudorandomReader(t *testing.T) {
tests := []struct {
seed []byte
expect []byte
}{
{
seed: []byte("seed0"),
expect: seed0out,
},
{
seed: []byte("seed1"),
expect: seed1out,
},
}
for _, c := range tests {
reader := gopherng.NewReader(c.seed)
o := make([]byte, 1024*2)
if _, err := io.ReadFull(reader, o); err != nil {
t.Fatal(err)
}
if !bytes.Equal(o, c.expect[:len(o)]) {
t.Errorf("expect and read data were not equal")
}
}
}