2016-01-12 10:52:40 +00:00
|
|
|
package protocol_test
|
2015-09-17 00:15:06 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-08-20 20:55:45 +02:00
|
|
|
. "v2ray.com/core/common/protocol"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2015-09-17 00:15:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateRandomInt64InRange(t *testing.T) {
|
2016-05-24 21:55:46 +02:00
|
|
|
assert := assert.On(t)
|
2016-01-12 11:38:43 +01:00
|
|
|
|
2015-09-17 00:15:06 +02:00
|
|
|
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-02-25 17:14:49 +01:00
|
|
|
v := int64(generator())
|
2015-09-17 00:15:06 +02:00
|
|
|
assert.Int64(v).AtMost(base + int64(delta))
|
|
|
|
assert.Int64(v).AtLeast(base - int64(delta))
|
|
|
|
}
|
|
|
|
}
|