diff options
| author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
|---|---|---|
| committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
| commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
| tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/pkg/math/rand/rand_test.go | |
| parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
| download | golang-8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1.tar.gz | |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/pkg/math/rand/rand_test.go')
| -rw-r--r-- | src/pkg/math/rand/rand_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/pkg/math/rand/rand_test.go b/src/pkg/math/rand/rand_test.go index 4d3abdb60..ab0dc49b4 100644 --- a/src/pkg/math/rand/rand_test.go +++ b/src/pkg/math/rand/rand_test.go @@ -322,6 +322,17 @@ func TestExpTables(t *testing.T) { } } +// For issue 6721, the problem came after 7533753 calls, so check 10e6. +func TestFloat32(t *testing.T) { + r := New(NewSource(1)) + for ct := 0; ct < 10e6; ct++ { + f := r.Float32() + if f >= 1 { + t.Fatal("Float32() should be in range [0,1). ct:", ct, "f:", f) + } + } +} + // Benchmarks func BenchmarkInt63Threadsafe(b *testing.B) { @@ -357,3 +368,31 @@ func BenchmarkInt31n1000(b *testing.B) { r.Int31n(1000) } } + +func BenchmarkFloat32(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Float32() + } +} + +func BenchmarkFloat64(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Float64() + } +} + +func BenchmarkPerm3(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Perm(3) + } +} + +func BenchmarkPerm30(b *testing.B) { + r := New(NewSource(1)) + for n := b.N; n > 0; n-- { + r.Perm(30) + } +} |
