random_test.go 367 B

1234567891011121314151617181920212223
  1. package stringx
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestRand(t *testing.T) {
  8. Seed(time.Now().UnixNano())
  9. assert.True(t, len(Rand()) > 0)
  10. assert.True(t, len(RandId()) > 0)
  11. const size = 10
  12. assert.True(t, len(Randn(size)) == size)
  13. }
  14. func BenchmarkRandString(b *testing.B) {
  15. for i := 0; i < b.N; i++ {
  16. _ = Randn(10)
  17. }
  18. }