| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package gae | |
| 6 | |
| 7 import ( | |
| 8 "math/rand" | |
| 9 "testing" | |
| 10 "time" | |
| 11 | |
| 12 "github.com/luci/luci-go/common/clock/testclock" | |
| 13 . "github.com/smartystreets/goconvey/convey" | |
| 14 "golang.org/x/net/context" | |
| 15 ) | |
| 16 | |
| 17 func TestMathRand(t *testing.T) { | |
| 18 t.Parallel() | |
| 19 | |
| 20 Convey("test mathrand", t, func() { | |
| 21 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) | |
| 22 c, _ := testclock.UseTime(context.Background(), now) | |
| 23 | |
| 24 // Note that the non-randomness below is because time is fixed a
t the | |
| 25 // top of the outer test function. Normally it would evolve with
time. | |
| 26 Convey("unset", func() { | |
| 27 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 28 i := r.Int() | |
| 29 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 30 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 31 }) | |
| 32 | |
| 33 Convey("set persistance", func() { | |
| 34 c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano(
)))) | |
| 35 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 36 So(GetMathRand(c).Int(), ShouldEqual, r.Int()) | |
| 37 So(GetMathRand(c).Int(), ShouldEqual, r.Int()) | |
| 38 }) | |
| 39 | |
| 40 Convey("nil set", func() { | |
| 41 c = SetMathRand(c, nil) | |
| 42 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 43 i := r.Int() | |
| 44 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 45 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 46 }) | |
| 47 }) | |
| 48 } | |
| OLD | NEW |