[Numpy-svn] r5516 - trunk/numpy/lib/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Jul 24 01:28:39 EDT 2008


Author: alan.mcintyre
Date: 2008-07-24 00:28:37 -0500 (Thu, 24 Jul 2008)
New Revision: 5516

Modified:
   trunk/numpy/lib/tests/test_financial.py
Log:
Added tests to improve coverage.
Converted tests from doctests to unit tests.


Modified: trunk/numpy/lib/tests/test_financial.py
===================================================================
--- trunk/numpy/lib/tests/test_financial.py	2008-07-24 04:29:40 UTC (rev 5515)
+++ trunk/numpy/lib/tests/test_financial.py	2008-07-24 05:28:37 UTC (rev 5516)
@@ -1,38 +1,57 @@
-"""
->>> np.round(np.rate(10,0,-3500,10000),4)==0.1107
-True
+from numpy.testing import *
+import numpy as np
 
->>> np.round(np.irr([-150000, 15000, 25000, 35000, 45000, 60000]),4)==0.0524
-True
+class TestFinancial(TestCase):
+    def test_rate(self):
+        assert_almost_equal(np.rate(10,0,-3500,10000), 
+                            0.1107, 4)
 
->>> np.round(np.pv(0.07,20,12000,0),2) == -127128.17
-True
+    def test_irr(self):
+        v = [-150000, 15000, 25000, 35000, 45000, 60000]
+        assert_almost_equal(np.irr(v),
+                            0.0524, 2)
 
->>> np.round(np.fv(0.075, 20, -2000,0,0),2) == 86609.36
-True
+    def test_pv(self):
+        assert_almost_equal(np.pv(0.07,20,12000,0), 
+                            -127128.17, 2)
 
->>> np.round(np.pmt(0.08/12,5*12,15000),3) == -304.146
-True
+    def test_fv(self):
+        assert_almost_equal(np.fv(0.075, 20, -2000,0,0),
+                            86609.36, 2)
 
->>> np.round(np.nper(0.075,-2000,0,100000.),2) == 21.54
-True
+    def test_pmt(self):
+        assert_almost_equal(np.pmt(0.08/12,5*12,15000),
+                            -304.146, 3)
 
->>> np.round(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]),2) == 117.04
-True
+    def test_nper(self):
+        assert_almost_equal(np.nper(0.075,-2000,0,100000.),
+                            21.54, 2)
 
->>> np.round(np.mirr([-4500,-800,800,800,600,600,800,800,700,3000],0.08,0.055),4) == 0.0665
-True
+    def test_nper(self):
+        assert_almost_equal(np.nper(0.0,-2000,0,100000.),
+                            50.0, 1)
 
->>> np.round(np.mirr([-120000,39000,30000,21000,37000,46000],0.10,0.12),4)==0.1344
-True
-"""
+    def test_npv(self):
+        assert_almost_equal(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]),
+                            117.04, 2)
 
-from numpy.testing import *
-import numpy as np
+    def test_mirr(self):
+        v1 = [-4500,-800,800,800,600,600,800,800,700,3000]
+        assert_almost_equal(np.mirr(v1,0.08,0.055),
+                            0.0665, 4)
 
-def test():
-    import doctest
-    doctest.testmod()
+        v2 = [-120000,39000,30000,21000,37000,46000]
+        assert_almost_equal(np.mirr(v2,0.10,0.12),
+                            0.1344, 4)
 
+
+def test_unimplemented():
+    # np.round(np.ppmt(0.1/12,1,60,55000),2) == 710.25
+    assert_raises(NotImplementedError, np.ppmt, 0.1/12, 1, 60, 55000)
+
+    # np.round(np.ipmt(0.1/12,1,24,2000),2) == 16.67
+    assert_raises(NotImplementedError, np.ipmt, 0.1/12, 1, 24, 2000)
+
+
 if __name__ == "__main__":
     run_module_suite()




More information about the Numpy-svn mailing list