Revision: 8038
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8038&view=rev
Author:   astraw
Date:     2009-12-18 22:25:16 +0000 (Fri, 18 Dec 2009)

Log Message:
-----------
tests: add unit test for prctile

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/tests/test_mlab.py

Modified: trunk/matplotlib/lib/matplotlib/tests/test_mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/tests/test_mlab.py  2009-12-17 19:31:21 UTC 
(rev 8037)
+++ trunk/matplotlib/lib/matplotlib/tests/test_mlab.py  2009-12-18 22:25:16 UTC 
(rev 8038)
@@ -32,3 +32,26 @@
 
     # the bad recarray should trigger a ValueError for having ndim > 1.
     mlab.rec2csv(bad,fd)
+
+def test_prctile():
+    # test odd lengths
+    x=[1,2,3]
+    assert mlab.prctile(x,50)==np.median(x)
+
+    # test even lengths
+    x=[1,2,3,4]
+    assert mlab.prctile(x,50)==np.median(x)
+
+    # derived from email sent by jason-sage to MPL-user on 20090914
+    ob1=[1,1,2,2,1,2,4,3,2,2,2,3,4,5,6,7,8,9,7,6,4,5,5]
+    p        = [0,   75, 100]
+    expected = [1,  5.5,   9]
+
+    # test vectorized
+    actual = mlab.prctile(ob1,p)
+    assert np.allclose( expected, actual )
+
+    # test scalar
+    for pi, expectedi in zip(p,expected):
+        actuali = mlab.prctile(ob1,pi)
+        assert np.allclose( expectedi, actuali )


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to