utils_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2014, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package common
  20. import (
  21. "testing"
  22. "time"
  23. )
  24. func TestMakeRandomPeriod(t *testing.T) {
  25. min := 1 * time.Nanosecond
  26. max := 10000 * time.Nanosecond
  27. res1, err := MakeRandomPeriod(min, max)
  28. if err != nil {
  29. t.Error("MakeRandomPeriod failed: %s", err)
  30. }
  31. if res1 < min {
  32. t.Error("duration should not be less than min")
  33. }
  34. if res1 > max {
  35. t.Error("duration should not be more than max")
  36. }
  37. res2, err := MakeRandomPeriod(min, max)
  38. if err != nil {
  39. t.Error("MakeRandomPeriod failed: %s", err)
  40. }
  41. if res1 == res2 {
  42. t.Error("duration should have randomness difference between calls")
  43. }
  44. }