util_test.go 569 B

123456789101112131415161718192021222324252627282930313233343536
  1. package util
  2. import (
  3. "testing"
  4. "github.com/nsqio/nsq/internal/test"
  5. )
  6. func BenchmarkUniqRands5of5(b *testing.B) {
  7. for i := 0; i < b.N; i++ {
  8. UniqRands(5, 5)
  9. }
  10. }
  11. func BenchmarkUniqRands20of20(b *testing.B) {
  12. for i := 0; i < b.N; i++ {
  13. UniqRands(20, 20)
  14. }
  15. }
  16. func BenchmarkUniqRands20of50(b *testing.B) {
  17. for i := 0; i < b.N; i++ {
  18. UniqRands(20, 50)
  19. }
  20. }
  21. func TestUniqRands(t *testing.T) {
  22. var x []int
  23. x = UniqRands(3, 10)
  24. test.Equal(t, 3, len(x))
  25. x = UniqRands(10, 5)
  26. test.Equal(t, 5, len(x))
  27. x = UniqRands(10, 20)
  28. test.Equal(t, 10, len(x))
  29. }