From 539681fffd96082ca3b5d18643d4f08f65c47170 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 5 Jul 2014 06:14:29 +0100 Subject: tests: Rename test scripts, changing - to _ for consistency. From now on, all new tests must use underscore. Addresses issue #727. --- tests/float/builtin-float-minmax.py | 26 -------- tests/float/builtin_float_minmax.py | 26 ++++++++ tests/float/int-divzero.py | 4 -- tests/float/int_divzero.py | 4 ++ tests/float/list-index.py | 8 --- tests/float/list_index.py | 8 +++ tests/float/math-fun-bool.py | 17 ----- tests/float/math-fun.py | 51 --------------- tests/float/math_fun.py | 51 +++++++++++++++ tests/float/math_fun_bool.py | 17 +++++ tests/float/string-format-modulo.py | 19 ------ tests/float/string-format.py | 123 ------------------------------------ tests/float/string_format.py | 123 ++++++++++++++++++++++++++++++++++++ tests/float/string_format_modulo.py | 19 ++++++ tests/float/true-value.py | 7 -- tests/float/true_value.py | 7 ++ 16 files changed, 255 insertions(+), 255 deletions(-) delete mode 100644 tests/float/builtin-float-minmax.py create mode 100644 tests/float/builtin_float_minmax.py delete mode 100644 tests/float/int-divzero.py create mode 100644 tests/float/int_divzero.py delete mode 100644 tests/float/list-index.py create mode 100644 tests/float/list_index.py delete mode 100644 tests/float/math-fun-bool.py delete mode 100644 tests/float/math-fun.py create mode 100644 tests/float/math_fun.py create mode 100644 tests/float/math_fun_bool.py delete mode 100644 tests/float/string-format-modulo.py delete mode 100644 tests/float/string-format.py create mode 100644 tests/float/string_format.py create mode 100644 tests/float/string_format_modulo.py delete mode 100644 tests/float/true-value.py create mode 100644 tests/float/true_value.py (limited to 'tests/float') diff --git a/tests/float/builtin-float-minmax.py b/tests/float/builtin-float-minmax.py deleted file mode 100644 index ce45a768a..000000000 --- a/tests/float/builtin-float-minmax.py +++ /dev/null @@ -1,26 +0,0 @@ -# test builtin min and max functions with float args - -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(min(1.5,-1.5)) -print(min(-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,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/builtin_float_minmax.py b/tests/float/builtin_float_minmax.py new file mode 100644 index 000000000..ce45a768a --- /dev/null +++ b/tests/float/builtin_float_minmax.py @@ -0,0 +1,26 @@ +# test builtin min and max functions with float args + +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(min(1.5,-1.5)) +print(min(-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,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/int-divzero.py b/tests/float/int-divzero.py deleted file mode 100644 index b037dd8c7..000000000 --- a/tests/float/int-divzero.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - 1 / 0 -except ZeroDivisionError: - print("ZeroDivisionError") diff --git a/tests/float/int_divzero.py b/tests/float/int_divzero.py new file mode 100644 index 000000000..b037dd8c7 --- /dev/null +++ b/tests/float/int_divzero.py @@ -0,0 +1,4 @@ +try: + 1 / 0 +except ZeroDivisionError: + print("ZeroDivisionError") diff --git a/tests/float/list-index.py b/tests/float/list-index.py deleted file mode 100644 index 13e4557af..000000000 --- a/tests/float/list-index.py +++ /dev/null @@ -1,8 +0,0 @@ -x = [1, 2] - -print(x[1]) - -try: - print(x[1.0]) -except TypeError: - print("TypeError") diff --git a/tests/float/list_index.py b/tests/float/list_index.py new file mode 100644 index 000000000..13e4557af --- /dev/null +++ b/tests/float/list_index.py @@ -0,0 +1,8 @@ +x = [1, 2] + +print(x[1]) + +try: + print(x[1.0]) +except TypeError: + print("TypeError") diff --git a/tests/float/math-fun-bool.py b/tests/float/math-fun-bool.py deleted file mode 100644 index 57232857a..000000000 --- a/tests/float/math-fun-bool.py +++ /dev/null @@ -1,17 +0,0 @@ -# Test the bool functions from math - -try: - from math import isfinite, isnan, isinf -except ImportError: - print("SKIP") - import sys - sys.exit() - -test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), - -float('NaN'), -float('Inf')] - -functions = [isfinite, isnan, isinf] - -for val in test_values: - for f in functions: - print(f(val)) diff --git a/tests/float/math-fun.py b/tests/float/math-fun.py deleted file mode 100644 index fa111e33e..000000000 --- a/tests/float/math-fun.py +++ /dev/null @@ -1,51 +0,0 @@ -# Tests the functions imported from math - -try: - from math import * -except ImportError: - print("SKIP") - import sys - sys.exit() - -test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] -p_test_values = [0.1, 0.5, 1.23456] -unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.] - -functions = [('sqrt', sqrt, p_test_values), - ('exp', exp, test_values), - ('expm1', expm1, test_values), - ('log', log, p_test_values), - ('log2', log2, p_test_values), - ('log10', log10, p_test_values), - ('cosh', cosh, test_values), - ('sinh', sinh, test_values), - ('tanh', tanh, test_values), - ('acosh', acosh, [1.0, 5.0, 1.0]), - ('asinh', asinh, test_values), - ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]), - ('cos', cos, test_values), - ('sin', sin, test_values), - ('tan', tan, test_values), - ('acos', acos, unit_range_test_values), - ('asin', asin, unit_range_test_values), - ('atan', atan, test_values), - ('ceil', ceil, test_values), - ('fabs', fabs, test_values), - ('floor', floor, test_values), - #('frexp', frexp, test_values), - ('trunc', trunc, test_values) - ] - -for function_name, function, test_vals in functions: - print(function_name) - for value in test_vals: - print("{:.7g}".format(function(value))) - -binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.), - (-23., -42.), (1., 0.0), (1., -0.0)]) - ] - -for function_name, function, test_vals in binary_functions: - print(function_name) - for value1, value2 in test_vals: - print("{:.7g}".format(function(value1, value2))) diff --git a/tests/float/math_fun.py b/tests/float/math_fun.py new file mode 100644 index 000000000..fa111e33e --- /dev/null +++ b/tests/float/math_fun.py @@ -0,0 +1,51 @@ +# Tests the functions imported from math + +try: + from math import * +except ImportError: + print("SKIP") + import sys + sys.exit() + +test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] +p_test_values = [0.1, 0.5, 1.23456] +unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.] + +functions = [('sqrt', sqrt, p_test_values), + ('exp', exp, test_values), + ('expm1', expm1, test_values), + ('log', log, p_test_values), + ('log2', log2, p_test_values), + ('log10', log10, p_test_values), + ('cosh', cosh, test_values), + ('sinh', sinh, test_values), + ('tanh', tanh, test_values), + ('acosh', acosh, [1.0, 5.0, 1.0]), + ('asinh', asinh, test_values), + ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]), + ('cos', cos, test_values), + ('sin', sin, test_values), + ('tan', tan, test_values), + ('acos', acos, unit_range_test_values), + ('asin', asin, unit_range_test_values), + ('atan', atan, test_values), + ('ceil', ceil, test_values), + ('fabs', fabs, test_values), + ('floor', floor, test_values), + #('frexp', frexp, test_values), + ('trunc', trunc, test_values) + ] + +for function_name, function, test_vals in functions: + print(function_name) + for value in test_vals: + print("{:.7g}".format(function(value))) + +binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.), + (-23., -42.), (1., 0.0), (1., -0.0)]) + ] + +for function_name, function, test_vals in binary_functions: + print(function_name) + for value1, value2 in test_vals: + print("{:.7g}".format(function(value1, value2))) diff --git a/tests/float/math_fun_bool.py b/tests/float/math_fun_bool.py new file mode 100644 index 000000000..57232857a --- /dev/null +++ b/tests/float/math_fun_bool.py @@ -0,0 +1,17 @@ +# Test the bool functions from math + +try: + from math import isfinite, isnan, isinf +except ImportError: + print("SKIP") + import sys + sys.exit() + +test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), + -float('NaN'), -float('Inf')] + +functions = [isfinite, isnan, isinf] + +for val in test_values: + for f in functions: + print(f(val)) diff --git a/tests/float/string-format-modulo.py b/tests/float/string-format-modulo.py deleted file mode 100644 index ddca0b555..000000000 --- a/tests/float/string-format-modulo.py +++ /dev/null @@ -1,19 +0,0 @@ -print("%s" % 1.0) -print("%r" % 1.0) - -print("%d" % 1.0) -print("%i" % 1.0) -print("%u" % 1.0) - -# these 3 have different behaviour in Python 3.x versions -# uPy raises a TypeError, following Python 3.5 (earlier versions don't) -#print("%x" % 18.0) -#print("%o" % 18.0) -#print("%X" % 18.0) - -print("%e" % 1.23456) -print("%E" % 1.23456) -print("%f" % 1.23456) -print("%F" % 1.23456) -print("%g" % 1.23456) -print("%G" % 1.23456) diff --git a/tests/float/string-format.py b/tests/float/string-format.py deleted file mode 100644 index b5ff68b8c..000000000 --- a/tests/float/string-format.py +++ /dev/null @@ -1,123 +0,0 @@ -# Change the following to True to get a much more comprehensive set of tests -# to run, albeit, which take considerably longer. - -full_tests = False - -def test(fmt, *args): - print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') - -test("{:10.4e}", 123.456) -test("{:10.4e}", -123.456) -test("{:10.4f}", 123.456) -test("{:10.4f}", -123.456) -test("{:10.4g}", 123.456) -test("{:10.4g}", -123.456) -test("{:e}", 100) -test("{:f}", 200) -test("{:g}", 300) - -test("{:10.4E}", 123.456) -test("{:10.4E}", -123.456) -test("{:10.4F}", 123.456) -test("{:10.4F}", -123.456) -test("{:10.4G}", 123.456) -test("{:10.4G}", -123.456) - -# The following fails right now -#test("{:10.1}", 0.0) - -def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): - fmt = '{' - if conv: - fmt += '!' - fmt += conv - fmt += ':' - if alignment: - fmt += fill - fmt += alignment - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - if fill == '0' and alignment == '=': - fmt = '{:' - fmt += sign - fmt += prefix - fmt += width - if precision: - fmt += '.' - fmt += precision - fmt += type - fmt += '}' - test(fmt, arg) - -eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, - -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, - 1e37, -1e37, 1e-37, -1e-37, - 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, - 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, - -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, - -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) - -if full_tests: - for type in ('e', 'E', 'g', 'G', 'n'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', '@', '0', ' '): - for sign in ('', '+', '-', ' '): - for prec in ('', '1', '3', '6'): - for num in eg_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - -# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) -# rounds differently than print("%.3f", 1.2345); - -f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, - 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, - -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, - -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) - -if full_tests: - for type in ('f', 'F'): - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in f_nums: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in int_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) - -pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) -pct_nums2 = (True, False, 1, 0, -1) - -if full_tests: - type = '%' - for width in ('', '4', '6', '8', '10'): - for alignment in ('', '<', '>', '=', '^'): - for fill in ('', ' ', '0', '@'): - for sign in ('', '+', '-', ' '): - # An empty precision defaults to 6, but when uPy is - # configured to use a float, we can only use a - # precision of 6 with numbers less than 10 and still - # get results that compare to CPython (which uses - # long doubles). - for prec in ('1', '2', '3'): - for num in pct_nums1: - test_fmt('', fill, alignment, sign, '', width, prec, type, num) - for num in pct_nums2: - test_fmt('', fill, alignment, sign, '', width, '', type, num) - -# We don't currently test a type of '' with floats (see the detailed comment -# in objstr.c) diff --git a/tests/float/string_format.py b/tests/float/string_format.py new file mode 100644 index 000000000..b5ff68b8c --- /dev/null +++ b/tests/float/string_format.py @@ -0,0 +1,123 @@ +# Change the following to True to get a much more comprehensive set of tests +# to run, albeit, which take considerably longer. + +full_tests = False + +def test(fmt, *args): + print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<') + +test("{:10.4e}", 123.456) +test("{:10.4e}", -123.456) +test("{:10.4f}", 123.456) +test("{:10.4f}", -123.456) +test("{:10.4g}", 123.456) +test("{:10.4g}", -123.456) +test("{:e}", 100) +test("{:f}", 200) +test("{:g}", 300) + +test("{:10.4E}", 123.456) +test("{:10.4E}", -123.456) +test("{:10.4F}", 123.456) +test("{:10.4F}", -123.456) +test("{:10.4G}", 123.456) +test("{:10.4G}", -123.456) + +# The following fails right now +#test("{:10.1}", 0.0) + +def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg): + fmt = '{' + if conv: + fmt += '!' + fmt += conv + fmt += ':' + if alignment: + fmt += fill + fmt += alignment + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + if fill == '0' and alignment == '=': + fmt = '{:' + fmt += sign + fmt += prefix + fmt += width + if precision: + fmt += '.' + fmt += precision + fmt += type + fmt += '}' + test(fmt, arg) + +eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0, + -0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10, + 1e37, -1e37, 1e-37, -1e-37, + 1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0, + 1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8, + -1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0, + -1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8) + +if full_tests: + for type in ('e', 'E', 'g', 'G', 'n'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', '@', '0', ' '): + for sign in ('', '+', '-', ' '): + for prec in ('', '1', '3', '6'): + for num in eg_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + +# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345) +# rounds differently than print("%.3f", 1.2345); + +f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, + 0.0012, 0.0123, 0.1234, 1.23459, 12.3456, + -0.0001, -0.001, -0.01, -0.1, -1.0, -10.0, + -0.0012, -0.0123, -0.1234, -1.23459, -12.3456) + +if full_tests: + for type in ('f', 'F'): + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in f_nums: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in int_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) + +pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99) +pct_nums2 = (True, False, 1, 0, -1) + +if full_tests: + type = '%' + for width in ('', '4', '6', '8', '10'): + for alignment in ('', '<', '>', '=', '^'): + for fill in ('', ' ', '0', '@'): + for sign in ('', '+', '-', ' '): + # An empty precision defaults to 6, but when uPy is + # configured to use a float, we can only use a + # precision of 6 with numbers less than 10 and still + # get results that compare to CPython (which uses + # long doubles). + for prec in ('1', '2', '3'): + for num in pct_nums1: + test_fmt('', fill, alignment, sign, '', width, prec, type, num) + for num in pct_nums2: + test_fmt('', fill, alignment, sign, '', width, '', type, num) + +# We don't currently test a type of '' with floats (see the detailed comment +# in objstr.c) diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py new file mode 100644 index 000000000..ddca0b555 --- /dev/null +++ b/tests/float/string_format_modulo.py @@ -0,0 +1,19 @@ +print("%s" % 1.0) +print("%r" % 1.0) + +print("%d" % 1.0) +print("%i" % 1.0) +print("%u" % 1.0) + +# these 3 have different behaviour in Python 3.x versions +# uPy raises a TypeError, following Python 3.5 (earlier versions don't) +#print("%x" % 18.0) +#print("%o" % 18.0) +#print("%X" % 18.0) + +print("%e" % 1.23456) +print("%E" % 1.23456) +print("%f" % 1.23456) +print("%F" % 1.23456) +print("%g" % 1.23456) +print("%G" % 1.23456) diff --git a/tests/float/true-value.py b/tests/float/true-value.py deleted file mode 100644 index df415f003..000000000 --- a/tests/float/true-value.py +++ /dev/null @@ -1,7 +0,0 @@ -# Test true-ish value handling - -if not 0.0: - print("float 0") - -if not 0+0j: - print("complex 0") diff --git a/tests/float/true_value.py b/tests/float/true_value.py new file mode 100644 index 000000000..df415f003 --- /dev/null +++ b/tests/float/true_value.py @@ -0,0 +1,7 @@ +# Test true-ish value handling + +if not 0.0: + print("float 0") + +if not 0+0j: + print("complex 0") -- cgit v1.2.3