2014-03-20 21:26:51 +00:00
|
|
|
# Tests the functions imported from math
|
|
|
|
|
2014-06-19 23:50:49 +01:00
|
|
|
try:
|
|
|
|
from math import *
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-08 05:00:57 +01:00
|
|
|
raise SystemExit
|
2014-03-20 21:26:51 +00:00
|
|
|
|
|
|
|
test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.]
|
2014-12-18 14:44:02 +00:00
|
|
|
test_values_small = [-10., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.] # so we don't overflow 32-bit precision
|
2014-03-20 21:26:51 +00:00
|
|
|
unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.]
|
|
|
|
|
2015-12-10 12:28:37 +00:00
|
|
|
functions = [('sqrt', sqrt, test_values),
|
2014-12-18 14:44:02 +00:00
|
|
|
('exp', exp, test_values_small),
|
2015-12-10 12:28:37 +00:00
|
|
|
('log', log, test_values),
|
2014-04-01 21:21:50 +01:00
|
|
|
('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),
|
2015-04-04 22:05:30 +01:00
|
|
|
('trunc', trunc, test_values),
|
|
|
|
('radians', radians, test_values),
|
|
|
|
('degrees', degrees, test_values),
|
2014-03-20 21:26:51 +00:00
|
|
|
]
|
|
|
|
|
2014-04-01 21:21:50 +01:00
|
|
|
for function_name, function, test_vals in functions:
|
|
|
|
print(function_name)
|
2014-03-20 21:26:51 +00:00
|
|
|
for value in test_vals:
|
2015-12-10 12:28:37 +00:00
|
|
|
try:
|
|
|
|
print("{:.5g}".format(function(value)))
|
|
|
|
except ValueError as e:
|
|
|
|
print(str(e))
|
2014-03-20 21:26:51 +00:00
|
|
|
|
2015-01-22 13:48:29 +00:00
|
|
|
tuple_functions = [('frexp', frexp, test_values),
|
|
|
|
('modf', modf, test_values),
|
|
|
|
]
|
|
|
|
|
|
|
|
for function_name, function, test_vals in tuple_functions:
|
|
|
|
print(function_name)
|
|
|
|
for value in test_vals:
|
|
|
|
x, y = function(value)
|
|
|
|
print("{:.5g} {:.5g}".format(x, y))
|
|
|
|
|
2014-04-01 21:21:50 +01:00
|
|
|
binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.),
|
2015-04-04 22:05:30 +01:00
|
|
|
(-23., -42.), (1., 0.0), (1., -0.0)]),
|
|
|
|
('pow', pow, ((1., 0.), (0., 1.), (2., 0.5), (-3., 5.), (-3., -4.),)),
|
|
|
|
('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),)),
|
2017-07-03 17:15:11 +01:00
|
|
|
('log', log, ((2., 2.), (3., 2.), (4., 5.), (0., 1.), (1., 0.), (-1., 1.), (1., -1.), (2., 1.))),
|
2014-03-20 21:26:51 +00:00
|
|
|
]
|
|
|
|
|
2014-04-01 21:21:50 +01:00
|
|
|
for function_name, function, test_vals in binary_functions:
|
|
|
|
print(function_name)
|
2014-03-22 14:39:33 +00:00
|
|
|
for value1, value2 in test_vals:
|
2015-12-10 12:28:37 +00:00
|
|
|
try:
|
|
|
|
print("{:.5g}".format(function(value1, value2)))
|
2017-07-03 17:15:11 +01:00
|
|
|
except (ValueError, ZeroDivisionError) as e:
|
|
|
|
print(type(e))
|