2016-01-12 05:52:40 -05:00
|
|
|
package protocol_test
|
2015-09-16 18:15:06 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
. "v2ray.com/core/common/protocol"
|
2017-10-24 10:15:35 -04:00
|
|
|
. "v2ray.com/ext/assert"
|
2015-09-16 18:15:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateRandomInt64InRange(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2016-01-12 05:38:43 -05:00
|
|
|
|
2015-09-16 18:15:06 -04:00
|
|
|
base := time.Now().Unix()
|
|
|
|
delta := 100
|
2016-02-25 11:14:49 -05:00
|
|
|
generator := NewTimestampGenerator(Timestamp(base), delta)
|
2015-09-16 18:15:06 -04:00
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
2016-11-27 11:01:44 -05:00
|
|
|
val := int64(generator())
|
2017-10-26 15:44:22 -04:00
|
|
|
assert(val, AtMost, base+int64(delta))
|
|
|
|
assert(val, AtLeast, base-int64(delta))
|
2015-09-16 18:15:06 -04:00
|
|
|
}
|
|
|
|
}
|