Permalink
Browse files

Added tests of consistency with the math module. Simpler code.

  • Loading branch information...
1 parent 54848c1 commit cc41cd5b53537e835b71dcd703eebaa0b9abec26 @lebigot committed Apr 23, 2012
Showing with 30 additions and 4 deletions.
  1. +28 −0 uncertainties/test_umath.py
  2. +2 −4 uncertainties/test_uncertainties.py
@@ -225,3 +225,31 @@ def test_math_module():
# fsum is special because it does not take a fixed number of
# variables:
assert umath.fsum([x, x]).nominal_value == -3
+
+ # The same exceptions should be generated when numbers with uncertainties
+ # are used:
+
+ try:
+ math.log(0)
+ except err_math:
+ pass
+ else:
+ raise Exception('Exception expected')
+ try:
+ umath.log(0)
+ except err_ufloat:
+ assert err_math.args == err_ufloat.args
+ else:
+ raise Exception('Exception expected')
+ try:
+ umath.log(uncertainties.ufloat((0, 0)))
+ except err_ufloat:
+ assert err_math.args == err_ufloat.args
+ else:
+ raise Exception('Exception expected')
+ try:
+ umath.log(uncertainties.ufloat((0, 1)))
+ except err_ufloat:
+ assert err_math.args == err_ufloat.args
+ else:
+ raise Exception('Exception expected')
@@ -710,16 +710,14 @@ def test_power():
pass
else:
raise Exception('An exception should have been raised')
-
try:
(-1)*9.1 == (-1)**9.1
except Exception as err_float:
- pass
+ # UFloat and floats should raise the same error:
+ assert err_ufloat.args == err_float.args
else:
raise Exception('An exception should have been raised')
- # UFloat and floats should raise the same error:
- assert err_ufloat.args == err_float.args
###############################################################################

0 comments on commit cc41cd5

Please sign in to comment.