package rand
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRandStr(t *testing.T) {
|
|
l := 243
|
|
s := Str(l)
|
|
assert.Equal(t, l, len(s))
|
|
}
|
|
|
|
func TestRandBytes(t *testing.T) {
|
|
l := 243
|
|
b := Bytes(l)
|
|
assert.Equal(t, l, len(b))
|
|
}
|
|
|
|
func BenchmarkRandBytes10B(b *testing.B) {
|
|
benchmarkRandBytes(b, 10)
|
|
}
|
|
func BenchmarkRandBytes100B(b *testing.B) {
|
|
benchmarkRandBytes(b, 100)
|
|
}
|
|
func BenchmarkRandBytes1KiB(b *testing.B) {
|
|
benchmarkRandBytes(b, 1024)
|
|
}
|
|
func BenchmarkRandBytes10KiB(b *testing.B) {
|
|
benchmarkRandBytes(b, 10*1024)
|
|
}
|
|
func BenchmarkRandBytes100KiB(b *testing.B) {
|
|
benchmarkRandBytes(b, 100*1024)
|
|
}
|
|
func BenchmarkRandBytes1MiB(b *testing.B) {
|
|
benchmarkRandBytes(b, 1024*1024)
|
|
}
|
|
|
|
func benchmarkRandBytes(b *testing.B, n int) {
|
|
for i := 0; i < b.N; i++ {
|
|
_ = Bytes(n)
|
|
}
|
|
b.ReportAllocs()
|
|
}
|