rand_test.go 600 B

12345678910111213141516171819202122232425
  1. package protocol_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/v2ray/v2ray-core/common/protocol"
  6. . "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
  7. v2testing "github.com/v2ray/v2ray-core/testing"
  8. "github.com/v2ray/v2ray-core/testing/assert"
  9. )
  10. func TestGenerateRandomInt64InRange(t *testing.T) {
  11. v2testing.Current(t)
  12. base := time.Now().Unix()
  13. delta := 100
  14. generator := NewRandomTimestampGenerator(protocol.Timestamp(base), delta)
  15. for i := 0; i < 100; i++ {
  16. v := int64(generator.Next())
  17. assert.Int64(v).AtMost(base + int64(delta))
  18. assert.Int64(v).AtLeast(base - int64(delta))
  19. }
  20. }