go.x2ox.com/sorbifolia/random@v0.0.0-20240520090142-6d8be5c4ed59/fast_test.go (about) 1 package random 2 3 import ( 4 "testing" 5 ) 6 7 func TestNewFastRand(t *testing.T) { 8 t.Parallel() 9 10 fr := Fast() 11 if len(fr.RandString(10)) != 10 { 12 t.Error("1") 13 } 14 15 fr = fr.SetRandBytes([]byte("123456")) 16 if len(fr.RandString(10)) != 10 { 17 t.Error("test fail") 18 } 19 } 20 21 func TestNewFastRandRepeatable(t *testing.T) { 22 t.Parallel() 23 24 defer func() { 25 if e := recover(); e == nil { 26 t.Error("test fail") 27 } 28 }() 29 30 Fast().SetRandBytes([]byte("11")).RandString(1) 31 } 32 33 func TestNewFastRandTooLong(t *testing.T) { 34 t.Parallel() 35 36 defer func() { 37 if e := recover(); e == nil { 38 t.Error("test fail") 39 } 40 }() 41 42 Fast().SetRandBytes(make([]byte, 257)).RandString(1) 43 } 44 45 func BenchmarkFastRand(b *testing.B) { 46 for i := 0; i < b.N; i++ { 47 Fast().RandString(1123) 48 } 49 } 50 51 func TestNewFastRandTooLon(t *testing.T) { 52 t.Parallel() 53 54 defer func() { 55 if e := recover(); e == nil { 56 t.Error("test fail") 57 } 58 }() 59 60 Fast().SetRandBytes(make([]byte, 257)).RandString(1) 61 } 62 63 func TestFastRand64(t *testing.T) { 64 t.Parallel() 65 66 _fastRand64() 67 }