Skip to content

Commit b1fa907

Browse files
committed
tests: Allow float tests to run when MATH_SPECIAL_FUNCTIONS is disabled.
1 parent 978d2e5 commit b1fa907

4 files changed

Lines changed: 45 additions & 11 deletions

File tree

tests/float/cmath_fun.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
('rect', rect, ((0, 0), (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, 1), (1, -1), (123., -456.))),
3333
('exp', exp, test_values),
3434
('log', log, test_values_non_zero),
35-
('log10', log10, test_values_non_zero),
3635
('sqrt', sqrt, test_values),
3736
('cos', cos, test_values),
3837
('sin', sin, test_values),

tests/float/cmath_fun_special.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# test the special functions imported from cmath
2+
3+
try:
4+
from cmath import *
5+
log10
6+
except (ImportError, NameError):
7+
print("SKIP")
8+
import sys
9+
sys.exit()
10+
11+
test_values_non_zero = []
12+
base_values = (0.0, 0.5, 1.2345, 10.)
13+
for r in base_values:
14+
for i in base_values:
15+
if r != 0. or i != 0.:
16+
test_values_non_zero.append(complex(r, i))
17+
if r != 0.:
18+
test_values_non_zero.append(complex(-r, i))
19+
if i != 0.:
20+
test_values_non_zero.append(complex(r, -i))
21+
if r != 0. and i != 0.:
22+
test_values_non_zero.append(complex(-r, -i))
23+
24+
functions = [
25+
('log10', log10, test_values_non_zero),
26+
]
27+
28+
for f_name, f, test_vals in functions:
29+
print(f_name)
30+
for val in test_vals:
31+
ret = f(val)
32+
print("complex(%.5g, %.5g)" % (ret.real, ret.imag))

tests/float/math_fun.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313

1414
functions = [('sqrt', sqrt, test_values),
1515
('exp', exp, test_values_small),
16-
('expm1', expm1, test_values_small),
1716
('log', log, test_values),
18-
('log2', log2, test_values),
19-
('log10', log10, test_values),
20-
('cosh', cosh, test_values_small),
21-
('sinh', sinh, test_values_small),
22-
('tanh', tanh, test_values_small),
23-
('acosh', acosh, [1.0, 5.0, 1.0]),
24-
('asinh', asinh, test_values),
25-
('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
2617
('cos', cos, test_values),
2718
('sin', sin, test_values),
2819
('tan', tan, test_values),

tests/float/math_fun_special.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
pos_test_values = [0.001, 0.1, 0.5, 1.0, 1.5, 10.,]
1313

1414
functions = [
15+
('expm1', expm1, test_values),
16+
('log2', log2, test_values),
17+
('log10', log10, test_values),
18+
('cosh', cosh, test_values),
19+
('sinh', sinh, test_values),
20+
('tanh', tanh, test_values),
21+
('acosh', acosh, [1.0, 5.0, 1.0]),
22+
('asinh', asinh, test_values),
23+
('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
1524
('erf', erf, test_values),
1625
('erfc', erfc, test_values),
1726
('gamma', gamma, pos_test_values),
@@ -21,4 +30,7 @@
2130
for function_name, function, test_vals in functions:
2231
print(function_name)
2332
for value in test_vals:
24-
print("{:.5g}".format(function(value)))
33+
try:
34+
print("{:.5g}".format(function(value)))
35+
except ValueError as e:
36+
print(str(e))

0 commit comments

Comments
 (0)