time_test.go 435 B

1234567891011121314151617181920212223
  1. package protocol_test
  2. import (
  3. "testing"
  4. "time"
  5. . "v2ray.com/core/common/protocol"
  6. . "v2ray.com/ext/assert"
  7. )
  8. func TestGenerateRandomInt64InRange(t *testing.T) {
  9. assert := With(t)
  10. base := time.Now().Unix()
  11. delta := 100
  12. generator := NewTimestampGenerator(Timestamp(base), delta)
  13. for i := 0; i < 100; i++ {
  14. val := int64(generator())
  15. assert(val, AtMost, base+int64(delta))
  16. assert(val, AtLeast, base-int64(delta))
  17. }
  18. }