Пример #1
0
def test_power_special_cases():
    '''
    Checks special cases of umath.pow().
    '''

    test_uncertainties.power_special_cases(umath.pow)

    # We want the same behavior for numbers with uncertainties and for
    # math.pow() at their nominal values:

    positive = ufloat(0.3, 0.01)
    negative = ufloat(-0.3, 0.01)

    # http://stackoverflow.com/questions/10282674/difference-between-the-built-in-pow-and-math-pow-for-floats-in-python

    try:
        umath.pow(ufloat(0, 0.1), negative)
    except (ValueError, OverflowError), err:  # Python 2.6+ "as err"
        err_type = type(err)  # For Python 3: err is destroyed after except
Пример #2
0
def test_power_special_cases():
    '''
    Checks special cases of umath.pow().
    '''
    
    test_uncertainties.power_special_cases(umath.pow)

    # We want the same behavior for numbers with uncertainties and for
    # math.pow() at their nominal values:

    positive = ufloat(0.3, 0.01)
    negative = ufloat(-0.3, 0.01)
    
    # http://stackoverflow.com/questions/10282674/difference-between-the-built-in-pow-and-math-pow-for-floats-in-python

    try:
        umath.pow(ufloat(0, 0.1), negative)
    except (ValueError, OverflowError), err:  # Python 2.6+ "as err"
        err_class = err.__class__  # For Python 3: err is destroyed after except
Пример #3
0
def test_power_special_cases():
    '''
    Checks special cases of umath.pow().
    '''
    
    test_uncertainties.power_special_cases(umath.pow)

    # We want the same behavior for numbers with uncertainties and for
    # math.pow() at their nominal values:

    positive = ufloat(0.3, 0.01)
    negative = ufloat(-0.3, 0.01)
    
    # http://stackoverflow.com/questions/10282674/difference-between-the-built-in-pow-and-math-pow-for-floats-in-python

    try:
        umath.pow(ufloat(0, 0.1), negative)
    except (ValueError, OverflowError) as err:
        err_class = err.__class__  # For Python 3: err is destroyed after except
    else:
        err_class = None
        
    err_msg = 'A proper exception should have been raised'

    # An exception must have occurred:
    assert err_class == ValueError, 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:
        raise Exception('A proper exception should have been raised')
Пример #4
0
def test_power_special_cases():
    '''
    Checks special cases of umath_core.pow().
    '''

    test_uncertainties.power_special_cases(umath_core.pow)

    # We want the same behavior for numbers with uncertainties and for
    # math.pow() at their nominal values:

    positive = ufloat(0.3, 0.01)
    negative = ufloat(-0.3, 0.01)

    # http://stackoverflow.com/questions/10282674/difference-between-the-built-in-pow-and-math-pow-for-floats-in-python

    try:
        umath_core.pow(ufloat(0, 0.1), negative)
    except (ValueError, OverflowError) as err:
        err_class = err.__class__  # For Python 3: err is destroyed after except
    else:
        err_class = None

    err_msg = 'A proper exception should have been raised'

    # An exception must have occurred:
    assert err_class == ValueError, err_msg

    try:
        result = umath_core.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:
        raise Exception('A proper exception should have been raised')
Пример #5
0
def test_power_special_cases():
    '''
    Checks special cases of umath_core.pow().
    '''

    test_uncertainties.power_special_cases(umath_core.pow)

    # We want the same behavior for numbers with uncertainties and for
    # math.pow() at their nominal values.

    positive = ufloat(0.3, 0.01)
    negative = ufloat(-0.3, 0.01)

    # The type of the expected exception is first determined, because
    # it varies between versions of Python (OverflowError in Python
    # 2.6+, ValueError in Python 2.5,...):
    try:
        math.pow(0, negative.nominal_value)
    except Exception, err_math:  # "as", for Python 2.6+
        # Python 3 does not make exceptions local variables: they are
        # restricted to their except block:
        err_math_args = err_math.args
        exception_class = err_math.__class__