def test_hypot(): ''' Special cases where derivatives cannot be calculated: ''' x = ufloat(0, 1) y = ufloat(0, 2) # Derivatives that cannot be calculated simply return NaN, with no # exception being raised, normally: result = umath_core.hypot(x, y) assert test_uncertainties.isnan(result.derivatives[x]) assert test_uncertainties.isnan(result.derivatives[y])
def test_hypot(): ''' Special cases where derivatives cannot be calculated: ''' x = ufloat(0, 1) y = ufloat(0, 2) # Derivatives that cannot be calculated simply return NaN, with no # exception being raised, normally: result = umath.hypot(x, y) assert test_uncertainties.isnan(result.derivatives[x]) assert test_uncertainties.isnan(result.derivatives[y])
err_msg = 'A proper exception should have been raised' # An exception must have occurred: if sys.version_info >= (2, 6): assert err_type == ValueError, err_msg else: assert err_type == OverflowError, err_msg try: result = umath.pow(negative, positive) except ValueError: # The reason why it should also fail in Python 3 is that the # result of Python 3 is a complex number, which uncertainties # does not handle (no uncertainties on complex numbers). In # Python 2, this should always fail, since Python 2 does not # know how to calculate it. pass else: if sys.version_info >= (2, 6): raise Exception('A proper exception should have been raised') else: assert test_uncertainties.isnan(result.nominal_value) assert test_uncertainties.isnan(result.std_dev) def test_power_wrt_ref(): ''' Checks special cases of the umath.pow() power operator. ''' test_uncertainties.power_wrt_ref(umath.pow, math.pow)
err_msg = 'A proper exception should have been raised' # An exception must have occurred: if sys.version_info >= (2, 6): assert err_class == ValueError, err_msg else: assert err_class == OverflowError, err_msg try: result = umath.pow(negative, positive) except ValueError: # The reason why it should also fail in Python 3 is that the # result of Python 3 is a complex number, which uncertainties # does not handle (no uncertainties on complex numbers). In # Python 2, this should always fail, since Python 2 does not # know how to calculate it. pass else: if sys.version_info >= (2, 6): raise Exception('A proper exception should have been raised') else: assert test_uncertainties.isnan(result.nominal_value) assert test_uncertainties.isnan(result.std_dev) def test_power_wrt_ref(): ''' Checks special cases of the umath.pow() power operator. ''' test_uncertainties.power_wrt_ref(umath.pow, math.pow)