From 505751c0aaf67033fff3f73b0c30b4dd6fde9d7b Mon Sep 17 00:00:00 2001 From: "Eric O. LEBIGOT (EOL)" Date: Fri, 26 Jul 2013 14:50:02 +0800 Subject: [PATCH] Added test for the new functions in umath.locally_cst_funcs. --- uncertainties/test_umath.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/uncertainties/test_umath.py b/uncertainties/test_umath.py index 2dfd6377..c0f10913 100644 --- a/uncertainties/test_umath.py +++ b/uncertainties/test_umath.py @@ -216,21 +216,24 @@ def test_math_module(): # math.factorial()): assert umath.factorial(4) == 24 - # Boolean functions: - assert not umath.isinf(x) - - # "is" is used instead of == because umath.isinf() must return - # a boolean, like math.isinf(): - assert umath.isinf(x) is False - - # "is" is used instead of == because umath.isnan() must return - # a boolean, like math.isnan(): - assert umath.isnan(x) is False - # fsum is special because it does not take a fixed number of # variables: assert umath.fsum([x, x]).nominal_value == -3 + # Functions that give locally constant results are tested: they + # should give the same result as their float equivalent: + for name in umath.locally_cst_funcs: + + try: + func = getattr(umath, name) + except AttributeError: + continue # Not in the math module, so not in umath either + + assert func(x) == func(x.nominal_value) + # The type should be left untouched. For example, isnan() + # should always give a boolean: + assert type(func(x)) == type(func(x.nominal_value)) + # The same exceptions should be generated when numbers with uncertainties # are used: