github.com/insolar/x-crypto@v0.0.0-20191031140942-75fab8a325f6/rand/rand_linux_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rand 6 7 import ( 8 "bytes" 9 "testing" 10 ) 11 12 func TestBatched(t *testing.T) { 13 fillBatched := batched(func(p []byte) bool { 14 for i := range p { 15 p[i] = byte(i) 16 } 17 return true 18 }, 5) 19 20 p := make([]byte, 13) 21 if !fillBatched(p) { 22 t.Fatal("batched function returned false") 23 } 24 expected := []byte{0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2} 25 if !bytes.Equal(expected, p) { 26 t.Errorf("incorrect batch result: got %x, want %x", p, expected) 27 } 28 } 29 30 func TestBatchedError(t *testing.T) { 31 b := batched(func(p []byte) bool { return false }, 5) 32 if b(make([]byte, 13)) { 33 t.Fatal("batched function should have returned false") 34 } 35 } 36 37 func TestBatchedEmpty(t *testing.T) { 38 b := batched(func(p []byte) bool { return false }, 5) 39 if !b(make([]byte, 0)) { 40 t.Fatal("empty slice should always return true") 41 } 42 }