1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-05 19:44:32 -04:00
v2fly/common/protocol/time_test.go

24 lines
481 B
Go
Raw Normal View History

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