summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_random.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-05-14 19:26:29 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-05-14 19:26:29 -0600
commit13b32e9d157a0ce62c0aa7d1447ad53fbb23d930 (patch)
tree60f38df366e020c4e7bc50156d8edc005bb2b2d8 /numpy/random/tests/test_random.py
parent677ff902eac3e4a1ad1d8c2c8488672a6907efea (diff)
parent6b1a1205eac6fe5d162f16155d500765e8bca53c (diff)
downloadnumpy-13b32e9d157a0ce62c0aa7d1447ad53fbb23d930.tar.gz
Merge pull request #4676 from juliantaylor/rand-seed-lim
BUG: reject too large seeds to RandomState
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r--numpy/random/tests/test_random.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index b6c4fe3af..ef4e7b127 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -7,6 +7,35 @@ from numpy.testing import (
from numpy import random
from numpy.compat import asbytes
+class TestSeed(TestCase):
+ def test_scalar(self):
+ s = np.random.RandomState(0)
+ assert_equal(s.randint(1000), 684)
+ s = np.random.RandomState(4294967295)
+ assert_equal(s.randint(1000), 419)
+
+ def test_array(self):
+ s = np.random.RandomState(range(10))
+ assert_equal(s.randint(1000), 468)
+ s = np.random.RandomState(np.arange(10))
+ assert_equal(s.randint(1000), 468)
+ s = np.random.RandomState([0])
+ assert_equal(s.randint(1000), 973)
+ s = np.random.RandomState([4294967295])
+ assert_equal(s.randint(1000), 265)
+
+ def test_invalid_scalar(self):
+ # seed must be a unsigned 32 bit integers
+ assert_raises(TypeError, np.random.RandomState, -0.5)
+ assert_raises(ValueError, np.random.RandomState, -1)
+
+ def test_invalid_array(self):
+ # seed must be a unsigned 32 bit integers
+ assert_raises(TypeError, np.random.RandomState, [-0.5])
+ assert_raises(ValueError, np.random.RandomState, [-1])
+ assert_raises(ValueError, np.random.RandomState, [4294967296])
+ assert_raises(ValueError, np.random.RandomState, [1, 2, 4294967296])
+ assert_raises(ValueError, np.random.RandomState, [1, -2, 4294967296])
class TestBinomial(TestCase):
def test_n_zero(self):