Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: go/src/infra/gae/libs/gae/mathrand_test.go

Issue 1226063003: Move dummy service implementations into their own package. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@abstract
Patch Set: move mathrand test Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698