2016-01-12 10:52:40 +00:00
|
|
|
package protocol_test
|
2015-09-16 22:15:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-01-15 11:43:06 +00:00
|
|
|
. "github.com/v2ray/v2ray-core/proxy/vmess/protocol"
|
2015-12-02 16:27:55 +00:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
2015-12-02 14:27:18 +00:00
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-09-16 22:15:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateRandomInt64InRange(t *testing.T) {
|
2015-12-02 14:27:18 +00:00
|
|
|
v2testing.Current(t)
|
2016-01-12 10:38:43 +00:00
|
|
|
|
2015-09-16 22:15:06 +00:00
|
|
|
base := time.Now().Unix()
|
|
|
|
delta := 100
|
2016-01-12 10:52:40 +00:00
|
|
|
generator := NewRandomTimestampGenerator(Timestamp(base), delta)
|
2015-09-16 22:15:06 +00:00
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
2016-01-12 10:38:43 +00:00
|
|
|
v := int64(generator.Next())
|
2015-09-16 22:15:06 +00:00
|
|
|
assert.Int64(v).AtMost(base + int64(delta))
|
|
|
|
assert.Int64(v).AtLeast(base - int64(delta))
|
|
|
|
}
|
|
|
|
}
|