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

Side by Side Diff: common/data/rand/mathrand/mathrand_test.go

Issue 2588213002: Use global rand.Rand instance in mathrand. (Closed)
Patch Set: Created 4 years 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
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package mathrand 5 package mathrand
6 6
7 import ( 7 import (
8 "math" 8 "math"
9 "math/rand" 9 "math/rand"
10 "testing" 10 "testing"
11 11
12 . "github.com/smartystreets/goconvey/convey" 12 . "github.com/smartystreets/goconvey/convey"
13 "golang.org/x/net/context" 13 "golang.org/x/net/context"
14 ) 14 )
15 15
16 func Test(t *testing.T) { 16 func Test(t *testing.T) {
17 t.Parallel() 17 t.Parallel()
18 18
19 Convey("test mathrand", t, func() { 19 Convey("test mathrand", t, func() {
20 c := context.Background() 20 c := context.Background()
21 21
22 Convey("unset", func() { 22 Convey("unset", func() {
23 // Just ensure doesn't crash. 23 // Just ensure doesn't crash.
24 So(Get(c).Int()+1 > 0, ShouldBeTrue) 24 So(Get(c).Int()+1 > 0, ShouldBeTrue)
25 So(WithGoRand(c, func(r *rand.Rand) error {
26 So(r.Int(), ShouldBeGreaterThanOrEqualTo, 0)
27 return nil
28 }), ShouldBeNil)
25 }) 29 })
26 30
27 Convey("set persistance", func() { 31 Convey("set persistance", func() {
28 c = Set(c, rand.New(rand.NewSource(12345))) 32 c = Set(c, rand.New(rand.NewSource(12345)))
29 r := rand.New(rand.NewSource(12345)) 33 r := rand.New(rand.NewSource(12345))
30 So(Get(c).Int(), ShouldEqual, r.Int()) 34 So(Get(c).Int(), ShouldEqual, r.Int())
31 So(Get(c).Int(), ShouldEqual, r.Int()) 35 So(Get(c).Int(), ShouldEqual, r.Int())
32 }) 36 })
33 37
34 Convey("nil set", func() { 38 Convey("nil set", func() {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 }) 112 })
109 return nil 113 return nil
110 }) 114 })
111 } 115 }
112 116
113 // BenchmarkStdlibDefaultSource-8 50000000 32.0 ns/ op 117 // BenchmarkStdlibDefaultSource-8 50000000 32.0 ns/ op
114 // BenchmarkOurDefaultSourceViaCtx-8 200000 10893 ns/ op 118 // BenchmarkOurDefaultSourceViaCtx-8 200000 10893 ns/ op
115 // BenchmarkOurDefaultSourceViaFunc-8 30000000 38.7 ns/ op 119 // BenchmarkOurDefaultSourceViaFunc-8 30000000 38.7 ns/ op
116 // BenchmarkOurInitializedSourceViaCtx-8 50000000 30.2 ns/ op 120 // BenchmarkOurInitializedSourceViaCtx-8 50000000 30.2 ns/ op
117 // BenchmarkOurInitializedSourceViaFunc-8 50000000 29.1 ns/ op 121 // BenchmarkOurInitializedSourceViaFunc-8 50000000 29.1 ns/ op
OLDNEW
« common/data/rand/mathrand/mathrand.go ('K') | « common/data/rand/mathrand/mathrand.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698