Chromium Code Reviews| 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 "golang.org/x/net/context" | |
| 13 | |
| 14 "github.com/luci/luci-go/common/clock/testclock" | |
| 15 | |
| 16 . "github.com/smartystreets/goconvey/convey" | |
| 17 ) | |
| 18 | |
| 19 func TestMathRand(t *testing.T) { | |
|
estaab
2015/07/13 18:26:35
I'm a little confused by this being here. This is
iannucci
2015/07/14 01:35:53
gae (for better or worse.. actually probably just
| |
| 20 t.Parallel() | |
| 21 | |
| 22 Convey("test mathrand", t, func() { | |
| 23 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) | |
| 24 c, _ := testclock.UseTime(context.Background(), now) | |
| 25 | |
| 26 // Note that the non-randomness below is because time is fixed a t the | |
| 27 // top of the outer test function. Normally it would evolve with time. | |
| 28 Convey("unset", func() { | |
| 29 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 30 i := r.Int() | |
| 31 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 32 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 33 }) | |
| 34 | |
| 35 Convey("set persistance", func() { | |
| 36 c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano( )))) | |
| 37 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 38 So(GetMathRand(c).Int(), ShouldEqual, r.Int()) | |
| 39 So(GetMathRand(c).Int(), ShouldEqual, r.Int()) | |
| 40 }) | |
| 41 | |
| 42 Convey("nil set", func() { | |
| 43 c = SetMathRand(c, nil) | |
| 44 r := rand.New(rand.NewSource(now.UnixNano())) | |
| 45 i := r.Int() | |
| 46 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 47 So(GetMathRand(c).Int(), ShouldEqual, i) | |
| 48 }) | |
| 49 }) | |
| 50 } | |
| OLD | NEW |