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

Side by Side Diff: mathrand_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint 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
« no previous file with comments | « mathrand.go ('k') | memcache.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 }
OLDNEW
« no previous file with comments | « mathrand.go ('k') | memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698