diff options
| author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
|---|---|---|
| committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
| commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
| tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/pkg/crypto/rand/util_test.go | |
| parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
| download | golang-upstream/1.4.tar.gz | |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/pkg/crypto/rand/util_test.go')
| -rw-r--r-- | src/pkg/crypto/rand/util_test.go | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/pkg/crypto/rand/util_test.go b/src/pkg/crypto/rand/util_test.go deleted file mode 100644 index 1e2a4dd84..000000000 --- a/src/pkg/crypto/rand/util_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2013 The Go 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 rand_test - -import ( - "crypto/rand" - "math/big" - "testing" -) - -// http://golang.org/issue/6849. -func TestPrimeSmall(t *testing.T) { - for n := 2; n < 10; n++ { - p, err := rand.Prime(rand.Reader, n) - if err != nil { - t.Fatalf("Can't generate %d-bit prime: %v", n, err) - } - if p.BitLen() != n { - t.Fatalf("%v is not %d-bit", p, n) - } - if !p.ProbablyPrime(32) { - t.Fatalf("%v is not prime", p) - } - } -} - -// Test that passing bits < 2 causes Prime to return nil, error -func TestPrimeBitsLt2(t *testing.T) { - if p, err := rand.Prime(rand.Reader, 1); p != nil || err == nil { - t.Errorf("Prime should return nil, error when called with bits < 2") - } -} - -func TestInt(t *testing.T) { - // start at 128 so the case of (max.BitLen() % 8) == 0 is covered - for n := 128; n < 140; n++ { - b := new(big.Int).SetInt64(int64(n)) - if i, err := rand.Int(rand.Reader, b); err != nil { - t.Fatalf("Can't generate random value: %v, %v", i, err) - } - } -} - -func testIntPanics(t *testing.T, b *big.Int) { - defer func() { - if err := recover(); err == nil { - t.Errorf("Int should panic when called with max <= 0: %v", b) - } - }() - rand.Int(rand.Reader, b) -} - -// Test that passing a new big.Int as max causes Int to panic -func TestIntEmptyMaxPanics(t *testing.T) { - b := new(big.Int) - testIntPanics(t, b) -} - -// Test that passing a negative value as max causes Int to panic -func TestIntNegativeMaxPanics(t *testing.T) { - b := new(big.Int).SetInt64(int64(-1)) - testIntPanics(t, b) -} |
