Index: go/src/infra/gae/libs/gae/mathrand_test.go |
diff --git a/go/src/infra/gae/libs/gae/mathrand_test.go b/go/src/infra/gae/libs/gae/mathrand_test.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4fea05ff1fdc89ccfe6dbfc8409b1551931d4b34 |
--- /dev/null |
+++ b/go/src/infra/gae/libs/gae/mathrand_test.go |
@@ -0,0 +1,50 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package gae |
+ |
+import ( |
+ "math/rand" |
+ "testing" |
+ "time" |
+ |
+ "golang.org/x/net/context" |
+ |
+ "github.com/luci/luci-go/common/clock/testclock" |
+ |
+ . "github.com/smartystreets/goconvey/convey" |
+) |
+ |
+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
|
+ t.Parallel() |
+ |
+ Convey("test mathrand", t, func() { |
+ now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC) |
+ c, _ := testclock.UseTime(context.Background(), now) |
+ |
+ // Note that the non-randomness below is because time is fixed at the |
+ // top of the outer test function. Normally it would evolve with time. |
+ Convey("unset", func() { |
+ r := rand.New(rand.NewSource(now.UnixNano())) |
+ i := r.Int() |
+ So(GetMathRand(c).Int(), ShouldEqual, i) |
+ So(GetMathRand(c).Int(), ShouldEqual, i) |
+ }) |
+ |
+ Convey("set persistance", func() { |
+ c = SetMathRand(c, rand.New(rand.NewSource(now.UnixNano()))) |
+ r := rand.New(rand.NewSource(now.UnixNano())) |
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int()) |
+ So(GetMathRand(c).Int(), ShouldEqual, r.Int()) |
+ }) |
+ |
+ Convey("nil set", func() { |
+ c = SetMathRand(c, nil) |
+ r := rand.New(rand.NewSource(now.UnixNano())) |
+ i := r.Int() |
+ So(GetMathRand(c).Int(), ShouldEqual, i) |
+ So(GetMathRand(c).Int(), ShouldEqual, i) |
+ }) |
+ }) |
+} |