Source file
src/crypto/rand/rand_batched_test.go
1
2
3
4
5
6
7
8 package rand
9
10 import (
11 "bytes"
12 "testing"
13 )
14
15 func TestBatched(t *testing.T) {
16 fillBatched := batched(func(p []byte) bool {
17 for i := range p {
18 p[i] = byte(i)
19 }
20 return true
21 }, 5)
22
23 p := make([]byte, 13)
24 if !fillBatched(p) {
25 t.Fatal("batched function returned false")
26 }
27 expected := []byte{0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2}
28 if !bytes.Equal(expected, p) {
29 t.Errorf("incorrect batch result: got %x, want %x", p, expected)
30 }
31 }
32
33 func TestBatchedError(t *testing.T) {
34 b := batched(func(p []byte) bool { return false }, 5)
35 if b(make([]byte, 13)) {
36 t.Fatal("batched function should have returned false")
37 }
38 }
39
40 func TestBatchedEmpty(t *testing.T) {
41 b := batched(func(p []byte) bool { return false }, 5)
42 if !b(make([]byte, 0)) {
43 t.Fatal("empty slice should always return true")
44 }
45 }
46
View as plain text