From 54de868a1a37b182a94f2d521fe2c695bf19ddea Mon Sep 17 00:00:00 2001 From: CloseChoice Date: Thu, 21 May 2020 12:29:57 +0200 Subject: add hypothesis test, fix bug of non-monotonic ordering of quantile function --- numpy/lib/tests/test_function_base.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index c415653e4..ea562b466 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -5,6 +5,10 @@ import decimal from fractions import Fraction import math import pytest +import hypothesis +from hypothesis.extra.numpy import arrays +import hypothesis.strategies as st + import numpy as np from numpy import ma @@ -3104,7 +3108,7 @@ class TestQuantile: np.quantile(np.arange(100.), p, interpolation="midpoint") assert_array_equal(p, p0) - def test_quantile_monotic(self): + def test_quantile_monotonic(self): # GH 14685 # test that the return value of quantile is monotonic if p0 is ordered p0 = np.arange(0, 1, 0.01) @@ -3112,6 +3116,15 @@ class TestQuantile: equals_sorted = np.sort(quantile) == quantile assert equals_sorted.all() + @hypothesis.given(arr=arrays(dtype=np.float, shape=st.integers(min_value=3, max_value=1000), + elements=st.floats(allow_infinity=False, allow_nan=False))) + def test_quantile_monotonic_hypo(self, arr): + p0 = np.arange(0, 1, 0.01) + quantile = np.quantile(arr, p0) + equals_sorted = np.sort(quantile) == quantile + assert equals_sorted.all() + + class TestMedian: def test_basic(self): -- cgit v1.2.1