summaryrefslogtreecommitdiff
path: root/numpy/random/tests
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-12-14 15:49:47 +0200
committerGitHub <noreply@github.com>2020-12-14 15:49:47 +0200
commite4feb7027e397925d220a10dd58b581b87ca1fec (patch)
treef8d7f9528c4e50b892800f280623b34adb18a4d2 /numpy/random/tests
parent30114c3b34feef351143fd4676839eaab93af931 (diff)
parenta3bb19df580454a6b98c34e29a00c271c2e411af (diff)
downloadnumpy-e4feb7027e397925d220a10dd58b581b87ca1fec.tar.gz
Merge pull request #17921 from bashtage/uniform-high-low-check
BUG: Enforce high >= low on uniform number generators
Diffstat (limited to 'numpy/random/tests')
-rw-r--r--numpy/random/tests/test_generator_mt19937.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py
index b69cd38d4..c4fb5883c 100644
--- a/numpy/random/tests/test_generator_mt19937.py
+++ b/numpy/random/tests/test_generator_mt19937.py
@@ -1666,6 +1666,21 @@ class TestRandomDist:
# DBL_MAX by increasing fmin a bit
random.uniform(low=np.nextafter(fmin, 1), high=fmax / 1e17)
+ def test_uniform_zero_range(self):
+ func = random.uniform
+ result = func(1.5, 1.5)
+ assert_allclose(result, 1.5)
+ result = func([0.0, np.pi], [0.0, np.pi])
+ assert_allclose(result, [0.0, np.pi])
+ result = func([[2145.12], [2145.12]], [2145.12, 2145.12])
+ assert_allclose(result, 2145.12 + np.zeros((2, 2)))
+
+ def test_uniform_neg_range(self):
+ func = random.uniform
+ assert_raises(ValueError, func, 2, 1)
+ assert_raises(ValueError, func, [1, 2], [1, 1])
+ assert_raises(ValueError, func, [[0, 1],[2, 3]], 2)
+
def test_scalar_exception_propagation(self):
# Tests that exceptions are correctly propagated in distributions
# when called with objects that throw exceptions when converted to