-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_test.go
57 lines (47 loc) · 1.04 KB
/
random_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
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/
package random
import (
"bytes"
"fmt"
"testing"
)
func TestUnit_Bytes(t *testing.T) {
size := 10
r1 := Bytes(size)
r2 := Bytes(size)
fmt.Println(string(r1), string(r2))
if len(r1) != size || len(r2) != size {
t.Errorf("invalid len, is not %d", size)
}
if bytes.Equal(r1, r2) {
t.Errorf("result is not random")
}
}
func TestUnit_BytesOf(t *testing.T) {
size := 10
src := []byte("1234567890")
r1 := BytesOf(size, src)
r2 := BytesOf(size, src)
fmt.Println(string(r1), string(r2))
if len(r1) != size || len(r2) != size {
t.Errorf("invalid len, is not %d", size)
}
if bytes.Equal(r1, r2) {
t.Errorf("result is not random")
}
}
func Benchmark_Bytes64(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Bytes(64)
}
}
func Benchmark_Bytes256(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Bytes(256)
}
}