diff options
Diffstat (limited to 'tests/float')
| -rw-r--r-- | tests/float/array_construct.py | 3 | ||||
| -rw-r--r-- | tests/float/builtin_float_minmax.py | 39 | ||||
| -rw-r--r-- | tests/float/bytearray_construct.py | 3 | ||||
| -rw-r--r-- | tests/float/bytes_construct.py | 3 | ||||
| -rw-r--r-- | tests/float/cmath_fun.py | 3 | ||||
| -rw-r--r-- | tests/float/cmath_fun_special.py | 3 | ||||
| -rw-r--r-- | tests/float/float_array.py | 3 | ||||
| -rw-r--r-- | tests/float/float_struct.py | 3 | ||||
| -rw-r--r-- | tests/float/int_big_float.py | 4 | ||||
| -rw-r--r-- | tests/float/math_fun.py | 9 | ||||
| -rw-r--r-- | tests/float/math_fun_bool.py | 3 | ||||
| -rw-r--r-- | tests/float/math_fun_int.py | 3 | ||||
| -rw-r--r-- | tests/float/math_fun_intbig.py | 3 | ||||
| -rw-r--r-- | tests/float/math_fun_special.py | 3 | ||||
| -rw-r--r-- | tests/float/string_format_modulo.py | 3 | ||||
| -rw-r--r-- | tests/float/string_format_modulo3.py | 3 | ||||
| -rw-r--r-- | tests/float/string_format_modulo3.py.exp | 3 |
17 files changed, 43 insertions, 51 deletions
diff --git a/tests/float/array_construct.py b/tests/float/array_construct.py index 7e01fd476..938675835 100644 --- a/tests/float/array_construct.py +++ b/tests/float/array_construct.py @@ -3,9 +3,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(array('f', array('h', [1, 2]))) print(array('d', array('f', [1, 2]))) diff --git a/tests/float/builtin_float_minmax.py b/tests/float/builtin_float_minmax.py index 42cfa6382..266ed133d 100644 --- a/tests/float/builtin_float_minmax.py +++ b/tests/float/builtin_float_minmax.py @@ -3,31 +3,30 @@ try: min max except: - import sys print("SKIP") - sys.exit() + raise SystemExit -print(min(0,1.0)) -print(min(1.0,0)) -print(min(0,-1.0)) -print(min(-1.0,0)) +print(min(0, 1.0)) +print(min(1.0, 0)) +print(min(0, -1.0)) +print(min(-1.0, 0)) -print(max(0,1.0)) -print(max(1.0,0)) -print(max(0,-1.0)) -print(max(-1.0,0)) +print(max(0, 1.0)) +print(max(1.0, 0)) +print(max(0, -1.0)) +print(max(-1.0, 0)) -print(min(1.5,-1.5)) -print(min(-1.5,1.5)) +print(min(1.5, -1.5)) +print(min(-1.5, 1.5)) -print(max(1.5,-1.5)) -print(max(-1.5,1.5)) +print(max(1.5, -1.5)) +print(max(-1.5, 1.5)) -print(min([1,2.9,4,0,-1,2])) -print(max([1,2.9,4,0,-1,2])) +print(min([1, 2.9, 4, 0, -1, 2])) +print(max([1, 2.9, 4, 0, -1, 2])) -print(min([1,2.9,4,6.5,-1,2])) -print(max([1,2.9,4,6.5,-1,2])) -print(min([1,2.9,4,-6.5,-1,2])) -print(max([1,2.9,4,-6.5,-1,2])) +print(min([1, 2.9, 4, 6.5, -1, 2])) +print(max([1, 2.9, 4, 6.5, -1, 2])) +print(min([1, 2.9, 4, -6.5, -1, 2])) +print(max([1, 2.9, 4, -6.5, -1, 2])) diff --git a/tests/float/bytearray_construct.py b/tests/float/bytearray_construct.py index db946a99d..e960d624e 100644 --- a/tests/float/bytearray_construct.py +++ b/tests/float/bytearray_construct.py @@ -3,8 +3,7 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(bytearray(array('f', [1, 2.3]))) diff --git a/tests/float/bytes_construct.py b/tests/float/bytes_construct.py index 8664d7296..0e4482e43 100644 --- a/tests/float/bytes_construct.py +++ b/tests/float/bytes_construct.py @@ -3,8 +3,7 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(bytes(array('f', [1, 2.3]))) diff --git a/tests/float/cmath_fun.py b/tests/float/cmath_fun.py index 3ebcf5918..ae5921c30 100644 --- a/tests/float/cmath_fun.py +++ b/tests/float/cmath_fun.py @@ -4,8 +4,7 @@ try: from cmath import * except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit # make sure these constants exist in cmath print("%.5g" % e) diff --git a/tests/float/cmath_fun_special.py b/tests/float/cmath_fun_special.py index 422964dd7..471fda8c0 100644 --- a/tests/float/cmath_fun_special.py +++ b/tests/float/cmath_fun_special.py @@ -5,8 +5,7 @@ try: log10 except (ImportError, NameError): print("SKIP") - import sys - sys.exit() + raise SystemExit test_values_non_zero = [] base_values = (0.0, 0.5, 1.2345, 10.) diff --git a/tests/float/float_array.py b/tests/float/float_array.py index 8bc963444..8c8edcff7 100644 --- a/tests/float/float_array.py +++ b/tests/float/float_array.py @@ -1,9 +1,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def test(a): print(a) diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index a36ccce38..c4c186b89 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -5,9 +5,8 @@ try: except: import struct except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit i = 1. + 1/2 # TODO: it looks like '=' format modifier is not yet supported diff --git a/tests/float/int_big_float.py b/tests/float/int_big_float.py index b1a26ca73..0bd166218 100644 --- a/tests/float/int_big_float.py +++ b/tests/float/int_big_float.py @@ -18,6 +18,10 @@ print("%.5g" % (i / 1.2)) # this should delegate to complex print("%.5g" % (i * 1.2j).imag) +# negative power should produce float +print("%.5g" % (i ** -1)) +print("%.5g" % ((2 + i - i) ** -3)) + try: i / 0 except ZeroDivisionError: diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py index d9f179587..2835b9bfb 100644 --- a/tests/float/math_fun.py +++ b/tests/float/math_fun.py @@ -4,8 +4,7 @@ try: from math import * except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] test_values_small = [-10., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.] # so we don't overflow 32-bit precision @@ -52,7 +51,7 @@ binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.) ('atan2', atan2, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)), ('fmod', fmod, ((1., 1.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)), ('ldexp', ldexp, ((1., 0), (0., 1), (2., 2), (3., -2), (-3., -4),)), - ('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.))), + ('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.), (2., 1.))), ] for function_name, function, test_vals in binary_functions: @@ -60,5 +59,5 @@ for function_name, function, test_vals in binary_functions: for value1, value2 in test_vals: try: print("{:.5g}".format(function(value1, value2))) - except ValueError as e: - print(str(e)) + except (ValueError, ZeroDivisionError) as e: + print(type(e)) diff --git a/tests/float/math_fun_bool.py b/tests/float/math_fun_bool.py index 57232857a..30ab14a52 100644 --- a/tests/float/math_fun_bool.py +++ b/tests/float/math_fun_bool.py @@ -4,8 +4,7 @@ try: from math import isfinite, isnan, isinf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), -float('NaN'), -float('Inf')] diff --git a/tests/float/math_fun_int.py b/tests/float/math_fun_int.py index ee54f0995..5cadbb1e5 100644 --- a/tests/float/math_fun_int.py +++ b/tests/float/math_fun_int.py @@ -4,8 +4,7 @@ try: import math except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit for fun in (math.ceil, math.floor, math.trunc): for x in (-1.6, -0.2, 0, 0.6, 1.4, float('inf'), float('nan')): diff --git a/tests/float/math_fun_intbig.py b/tests/float/math_fun_intbig.py index 962c10daa..697ca7a6d 100644 --- a/tests/float/math_fun_intbig.py +++ b/tests/float/math_fun_intbig.py @@ -4,8 +4,7 @@ try: import math except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit for fun in (math.ceil, math.floor, math.trunc): for x in (-1e25, 1e25): diff --git a/tests/float/math_fun_special.py b/tests/float/math_fun_special.py index 32249b423..c3665a7cd 100644 --- a/tests/float/math_fun_special.py +++ b/tests/float/math_fun_special.py @@ -5,8 +5,7 @@ try: erf except (ImportError, NameError): print("SKIP") - import sys - sys.exit() + raise SystemExit test_values = [-8., -2.5, -1, -0.5, 0.0, 0.5, 2.5, 8.,] pos_test_values = [0.001, 0.1, 0.5, 1.0, 1.5, 10.,] diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py index 03c8dd00a..aea534247 100644 --- a/tests/float/string_format_modulo.py +++ b/tests/float/string_format_modulo.py @@ -44,3 +44,6 @@ print(('%.40g' % 1e-3)[:2]) print(('%.40g' % 1e-4)[:2]) print("%.0g" % 1) # 0 precision 'g' + +print('%.1e' % 9.99) # round up with positive exponent +print('%.1e' % 0.999) # round up with negative exponent diff --git a/tests/float/string_format_modulo3.py b/tests/float/string_format_modulo3.py index 563964786..5d26f2575 100644 --- a/tests/float/string_format_modulo3.py +++ b/tests/float/string_format_modulo3.py @@ -1,4 +1,3 @@ # uPy and CPython outputs differ for the following print("%.1g" % -9.9) # round up 'g' with '-' sign -print("%.1e" % 9.99) # round up with positive exponent -print("%.1e" % 0.999) # round up with negative exponent +print("%.2g" % 99.9) # round up diff --git a/tests/float/string_format_modulo3.py.exp b/tests/float/string_format_modulo3.py.exp index b158c7d7f..71432b340 100644 --- a/tests/float/string_format_modulo3.py.exp +++ b/tests/float/string_format_modulo3.py.exp @@ -1,3 +1,2 @@ -10 -1.00e+01 -1.00e-00 +100 |
