/go/gocont/src/randomstring/randomstring_test.go

https://bitbucket.org/jmilet/pruebasconcepto · Go · 37 lines · 27 code · 9 blank · 1 comment · 7 complexity · decef5c100298da6c4328a4a2c2ec45f MD5 · raw file

  1. package randomstring_test
  2. import (
  3. . "randomstring"
  4. "testing"
  5. )
  6. func TestRandomString(t *testing.T) {
  7. total := 20
  8. res := RandStringRunes(total)
  9. if len(res) != total {
  10. t.Fatalf("Expected %d and got %d", total, len(res))
  11. }
  12. total = 0
  13. res = RandStringRunes(total)
  14. if len(res) != total {
  15. t.Fatalf("Expected %d and got %d", total, len(res))
  16. }
  17. }
  18. // Silly test, just to ease a run...
  19. func TestRandomStringHighVolume(t *testing.T) {
  20. d := make(map[string]int)
  21. total := 1000000
  22. for i := 0; i < total; i++ {
  23. d[RandStringRunes(20)] += 1
  24. }
  25. if len(d) != total {
  26. t.Fatalf("Expected %d and got %d", total, len(d))
  27. }
  28. }