diff options
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r-- | numpy/random/tests/test_random.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 37bd121f3..c5f79d2c1 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -1,4 +1,3 @@ -from __future__ import division, absolute_import, print_function import warnings import numpy as np @@ -11,7 +10,7 @@ from numpy import random import sys -class TestSeed(object): +class TestSeed: def test_scalar(self): s = np.random.RandomState(0) assert_equal(s.randint(1000), 684) @@ -50,7 +49,7 @@ class TestSeed(object): [4, 5, 6]]) -class TestBinomial(object): +class TestBinomial: def test_n_zero(self): # Tests the corner case of n == 0 for the binomial distribution. # binomial(0, p) should be zero for any p in [0, 1]. @@ -65,7 +64,7 @@ class TestBinomial(object): assert_raises(ValueError, random.binomial, 1, np.nan) -class TestMultinomial(object): +class TestMultinomial: def test_basic(self): random.multinomial(100, [0.2, 0.8]) @@ -92,8 +91,14 @@ class TestMultinomial(object): assert_raises(TypeError, np.random.multinomial, 1, p, float(1)) + def test_multidimensional_pvals(self): + assert_raises(ValueError, np.random.multinomial, 10, [[0, 1]]) + assert_raises(ValueError, np.random.multinomial, 10, [[0], [1]]) + assert_raises(ValueError, np.random.multinomial, 10, [[[0], [1]], [[1], [0]]]) + assert_raises(ValueError, np.random.multinomial, 10, np.array([[0, 1], [1, 0]])) -class TestSetState(object): + +class TestSetState: def setup(self): self.seed = 1234567890 self.prng = random.RandomState(self.seed) @@ -141,7 +146,7 @@ class TestSetState(object): self.prng.negative_binomial(0.5, 0.5) -class TestRandint(object): +class TestRandint: rfunc = np.random.randint @@ -269,7 +274,7 @@ class TestRandint(object): sample = self.rfunc(lbnd, ubnd, dtype=dt) assert_equal(sample.dtype, np.dtype(dt)) - for dt in (bool, int, np.long): + for dt in (bool, int, np.compat.long): lbnd = 0 if dt is bool else np.iinfo(dt).min ubnd = 2 if dt is bool else np.iinfo(dt).max + 1 @@ -279,7 +284,7 @@ class TestRandint(object): assert_equal(type(sample), dt) -class TestRandomDist(object): +class TestRandomDist: # Make sure the random distribution returns the correct value for a # given seed @@ -974,7 +979,7 @@ class TestRandomDist(object): assert_array_equal(actual, desired) -class TestBroadcast(object): +class TestBroadcast: # tests that functions that broadcast behave # correctly when presented with non-scalar arguments def setup(self): @@ -1544,7 +1549,7 @@ class TestBroadcast(object): assert_raises(ValueError, logseries, bad_p_two * 3) -class TestThread(object): +class TestThread: # make sure each state produces the same sequence even in threads def setup(self): self.seeds = range(4) @@ -1588,7 +1593,7 @@ class TestThread(object): # See Issue #4263 -class TestSingleEltArrayInput(object): +class TestSingleEltArrayInput: def setup(self): self.argOne = np.array([2]) self.argTwo = np.array([3]) |