-
Notifications
You must be signed in to change notification settings - Fork 1
/
source_test.go
47 lines (40 loc) · 912 Bytes
/
source_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
package cryptorand_test
import (
"bytes"
"testing"
"github.com/wadey/cryptorand"
)
func TestSource(t *testing.T) {
s := cryptorand.Source
if s.Int63() == s.Int63() {
t.Error("Expected Int63() to be random")
}
}
func TestNewSource(t *testing.T) {
b := bytes.NewReader(make([]byte, 8))
s := cryptorand.NewSource(b)
if s.Int63() != 0 {
t.Error("Expected Int63() to be 0 with custom io.Reader")
}
b = bytes.NewReader([]byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})
s = cryptorand.NewSource(b)
if s.Int63() != 1<<63-1 {
t.Error("Expected Int63() to be max with custom io.Reader")
}
}
func TestSeedPanics(t *testing.T) {
defer func() {
if err := recover(); err == nil {
t.Error("Expected Seed() to panic")
}
}()
s := cryptorand.Source
s.Seed(1)
}
func BenchmarkRandSource(b *testing.B) {
s := cryptorand.Source
b.SetBytes(8)
for i := 0; i < b.N; i++ {
s.Int63()
}
}