random_test.go 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package rand
  7. import "testing"
  8. func TestRandomString(t *testing.T) {
  9. for _, l := range []int{0, 1, 2, 3, 4, 8, 42} {
  10. s := String(l)
  11. if len(s) != l {
  12. t.Errorf("Incorrect length %d != %d", len(s), l)
  13. }
  14. }
  15. strings := make([]string, 1000)
  16. for i := range strings {
  17. strings[i] = String(8)
  18. for j := range strings {
  19. if i == j {
  20. continue
  21. }
  22. if strings[i] == strings[j] {
  23. t.Errorf("Repeated random string %q", strings[i])
  24. }
  25. }
  26. }
  27. }
  28. func TestRandomUint64(t *testing.T) {
  29. ints := make([]uint64, 1000)
  30. for i := range ints {
  31. ints[i] = Uint64()
  32. for j := range ints {
  33. if i == j {
  34. continue
  35. }
  36. if ints[i] == ints[j] {
  37. t.Errorf("Repeated random int64 %d", ints[i])
  38. }
  39. }
  40. }
  41. }