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

Skip to content

Commit cdd5fac

Browse files
committed
tests: add unit test for prctile
svn path=/trunk/matplotlib/; revision=8038
1 parent 559d552 commit cdd5fac

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

lib/matplotlib/tests/test_mlab.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,26 @@ def test_rec2csv_bad_shape():
3232

3333
# the bad recarray should trigger a ValueError for having ndim > 1.
3434
mlab.rec2csv(bad,fd)
35+
36+
def test_prctile():
37+
# test odd lengths
38+
x=[1,2,3]
39+
assert mlab.prctile(x,50)==np.median(x)
40+
41+
# test even lengths
42+
x=[1,2,3,4]
43+
assert mlab.prctile(x,50)==np.median(x)
44+
45+
# derived from email sent by jason-sage to MPL-user on 20090914
46+
ob1=[1,1,2,2,1,2,4,3,2,2,2,3,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 np.allclose( expected, actual )
53+
54+
# test scalar
55+
for pi, expectedi in zip(p,expected):
56+
actuali = mlab.prctile(ob1,pi)
57+
assert np.allclose( expectedi, actuali )

0 commit comments

Comments
 (0)