-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrndbytes_test.go
More file actions
77 lines (64 loc) · 1.59 KB
/
rndbytes_test.go
File metadata and controls
77 lines (64 loc) · 1.59 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package rndbytes_test
import (
"github.com/SergeyMosin/rndbytes"
"testing"
)
func TestGetBytes(t *testing.T) {
mapSize := 10000000
stringKeySize := 48
strMap := make(map[string]int, mapSize)
intMap := make(map[int]bool, mapSize)
str := ""
allowFirstDash := false
for i := 0; i < mapSize; i++ {
//goland:noinspection GoBoolExpressions
str = string(rndbytes.GetBytes(stringKeySize, allowFirstDash))
n := rndbytes.GetInt()
//goland:noinspection GoBoolExpressions
if !allowFirstDash && str[0] == '-' {
t.Fatal("error: first dash is not allowed, str: "+str+", i:", i)
}
if _, ok := strMap[str]; ok {
t.Fatal("error: duplicate str key")
}
strMap[str] = n
if _, ok := intMap[n]; ok {
t.Fatal("error: duplicate int key")
}
intMap[n] = true
}
t.Log("Done:", str, strMap[str], intMap[strMap[str]])
}
func TestGetBytesPrint(t *testing.T) {
for i := 0; i < 100; i++ {
t.Log(string(rndbytes.GetBytes(42, false)))
}
t.Log("------------------------------------------------------")
for i := 0; i < 100; i++ {
t.Log(string(rndbytes.GetBytes(42, true)))
}
}
func BenchmarkGetBytesNoDash42(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = rndbytes.GetBytes(42, false)
}
}
func BenchmarkGetBytes42(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = rndbytes.GetBytes(42, true)
}
}
func BenchmarkGetBytes1500(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = rndbytes.GetBytes(1500, true)
}
}
func BenchmarkGetBytesNoDash1500(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
_ = rndbytes.GetBytes(1500, false)
}
}