1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 19:45:24 +00:00
v2fly/common/protocol/time_test.go

22 lines
448 B
Go
Raw Normal View History

2016-01-12 10:52:40 +00:00
package protocol_test
2015-09-16 22:15:06 +00:00
import (
"testing"
"time"
2016-08-20 18:55:45 +00:00
. "v2ray.com/core/common/protocol"
2015-09-16 22:15:06 +00:00
)
func TestGenerateRandomInt64InRange(t *testing.T) {
base := time.Now().Unix()
delta := 100
2016-02-25 16:14:49 +00:00
generator := NewTimestampGenerator(Timestamp(base), delta)
2015-09-16 22:15:06 +00:00
for i := 0; i < 100; i++ {
2016-11-27 16:01:44 +00:00
val := int64(generator())
2019-01-08 22:27:02 +00:00
if val > base+int64(delta) || val < base-int64(delta) {
t.Error(val, " not between ", base-int64(delta), " and ", base+int64(delta))
}
2015-09-16 22:15:06 +00:00
}
}