Changeset 2314
- Timestamp:
- Feb 1, 2006, 3:27:53 PM (19 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_util.py
r1932 r2314 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose 5 from Numeric import zeros, array, allclose, Float 6 6 from math import sqrt, pi 7 7 … … 974 974 def test_apply_expression_to_dictionary(self): 975 975 976 #FIXME: Division is not expected to work for integers. 977 #This must be caught. 976 978 foo = array([[1,2,3], 977 [4,5,6]] )979 [4,5,6]], Float) 978 980 979 981 bar = array([[-1,0,5], 980 [6,1,1]] )982 [6,1,1]], Float) 981 983 982 984 D = {'X': foo, 'Y': bar} … … 990 992 Z = apply_expression_to_dictionary('4*X+Y', D) 991 993 assert allclose(Z, 4*foo+bar) 994 995 # test zero division is OK 996 Z = apply_expression_to_dictionary('X/Y', D) 997 assert allclose(1/Z, 1/(foo/bar)) # can't compare inf to inf 998 999 # make an error for zero on zero 1000 # this is really an error in Numeric, SciPy core can handle it 1001 # Z = apply_expression_to_dictionary('0/Y', D) 992 1002 993 1003 #Check exceptions … … 1046 1056 if __name__ == "__main__": 1047 1057 suite = unittest.makeSuite(Test_Util,'test') 1048 #suite = unittest.makeSuite(Test_Util,'test_ file_function_time')1058 #suite = unittest.makeSuite(Test_Util,'test_apply') 1049 1059 runner = unittest.TextTestRunner() 1050 1060 runner.run(suite) -
inundation/pyvolution/util.py
r2074 r2314 509 509 will be evaluated by expression. 510 510 Values in dictionary must support operators given in 511 expression e.g. by overloading 511 expression e.g. by overloading 512 513 due to a limitation with Numeric, this can not evaluate 0/0 514 In general, the user can fix by adding 1e-30 to the numerator. 515 SciPy core can handle this situation. 512 516 """ 513 517 … … 532 536 msg = 'Expression "%s" could not be evaluated: %s' %(expression, e) 533 537 raise NameError, msg 538 except ValueError, e: 539 msg = 'Expression "%s" could not be evaluated: %s' %(expression, e) 540 raise ValueError, msg 534 541 535 542
Note: See TracChangeset
for help on using the changeset viewer.