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