Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4018b6a

Browse files
committed
TST: Parametrize test_prctile.
1 parent c86bcb1 commit 4018b6a

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

lib/matplotlib/tests/test_mlab.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ def test_colinear_pca():
3232
assert_allclose(pca.Y[:, 2:], 0., atol=1e-8)
3333

3434

35-
def test_prctile():
35+
@pytest.mark.parametrize('input', [
3636
# test odd lengths
37-
x = [1, 2, 3]
38-
assert mlab.prctile(x, 50) == np.median(x)
39-
37+
[1, 2, 3],
4038
# test even lengths
41-
x = [1, 2, 3, 4]
42-
assert mlab.prctile(x, 50) == np.median(x)
43-
39+
[1, 2, 3, 4],
4440
# derived from email sent by jason-sage to MPL-user on 20090914
45-
ob1 = [1, 1, 2, 2, 1, 2, 4, 3, 2, 2, 2, 3,
46-
4, 5, 6, 7, 8, 9, 7, 6, 4, 5, 5]
47-
p = [0, 75, 100]
48-
expected = [1, 5.5, 9]
49-
50-
# test vectorized
51-
actual = mlab.prctile(ob1, p)
52-
assert_allclose(expected, actual)
53-
54-
# test scalar
55-
for pi, expectedi in zip(p, expected):
56-
actuali = mlab.prctile(ob1, pi)
57-
assert_allclose(expectedi, actuali)
41+
[1, 1, 2, 2, 1, 2, 4, 3, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 7, 6, 4, 5, 5],
42+
],
43+
ids=[
44+
'odd length',
45+
'even length',
46+
'custom data',
47+
])
48+
@pytest.mark.parametrize('percentile', [
49+
0,
50+
50,
51+
75,
52+
100,
53+
[0, 75, 100],
54+
])
55+
def test_prctile(input, percentile):
56+
assert_allclose(mlab.prctile(input, percentile),
57+
np.percentile(input, percentile))
5858

5959

6060
def test_norm():

0 commit comments

Comments
 (0)