Author: Alexander Hesse <[email protected]>
Branch: split-rpython
Changeset: r59878:616f56ea2576
Date: 2013-01-08 23:08 +0100
http://bitbucket.org/pypy/pypy/changeset/616f56ea2576/
Log: Moved MathTests to test_ll_math
diff --git a/pypy/module/math/test/test_direct.py
b/pypy/module/math/test/test_direct.py
--- a/pypy/module/math/test/test_direct.py
+++ b/pypy/module/math/test/test_direct.py
@@ -4,220 +4,17 @@
import py, sys, math
from rpython.rlib import rfloat
from rpython.rlib.rfloat import isinf, isnan, INFINITY, NAN
+from rpython.rtyper.lltypesystem.module.test.test_ll_math import (MathTests,
+ getTester)
consistent_host = True
if '__pypy__' not in sys.builtin_module_names:
if sys.version_info < (2, 6):
consistent_host = False
-def positiveinf(x):
- return isinf(x) and x > 0.0
-
-def negativeinf(x):
- return isinf(x) and x < 0.0
-
-def finite(x):
- return not isinf(x) and not isnan(x)
-
-
-unary_math_functions = ['acos', 'asin', 'atan',
- 'ceil', 'cos', 'cosh', 'exp', 'fabs', 'floor',
- 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'log', 'log10',
- 'acosh', 'asinh', 'atanh', 'log1p', 'expm1']
-binary_math_functions = ['atan2', 'fmod', 'hypot', 'pow']
-
-
-class MathTests:
-
- REGCASES = []
- for name in unary_math_functions:
- try:
- input, output = (0.3,), getattr(math, name)(0.3)
- except AttributeError:
- # cannot test this function
- continue
- except ValueError:
- input, output = (1.3,), getattr(math, name)(1.3)
- REGCASES.append((name, input, output))
-
- IRREGCASES = [
- ('atan2', (0.31, 0.123), math.atan2(0.31, 0.123)),
- ('fmod', (0.31, 0.123), math.fmod(0.31, 0.123)),
- ('hypot', (0.31, 0.123), math.hypot(0.31, 0.123)),
- ('pow', (0.31, 0.123), math.pow(0.31, 0.123)),
- ('pow', (-0.31, 0.123), ValueError),
- ('pow', (-0.5, 2.0), 0.25),
- ('pow', (-0.5, 1.0), -0.5),
- ('pow', (-0.5, 0.0), 1.0),
- ('pow', (-0.5, -1.0), -2.0),
- ('ldexp', (3.375, 2), 13.5),
- ('ldexp', (1.0, -10000), 0.0), # underflow
- ('frexp', (-1.25,), lambda x: x == (-0.625, 1)),
- ('modf', (4.25,), lambda x: x == (0.25, 4.0)),
- ('modf', (-4.25,), lambda x: x == (-0.25, -4.0)),
- ('copysign', (1.5, 0.0), 1.5),
- ('copysign', (1.5, -0.0), -1.5),
- ('copysign', (1.5, INFINITY), 1.5),
- ('copysign', (1.5, -INFINITY), -1.5),
- ]
- if sys.platform != 'win32': # all NaNs seem to be negative there...?
- IRREGCASES += [
- ('copysign', (1.5, NAN), 1.5),
- ('copysign', (1.75, -NAN), -1.75), # special case for -NAN here
- ]
-
- OVFCASES = [
- ('cosh', (9999.9,), OverflowError),
- ('sinh', (9999.9,), OverflowError),
- ('exp', (9999.9,), OverflowError),
- ('pow', (10.0, 40000.0), OverflowError),
- ('ldexp', (10.0, 40000), OverflowError),
- ('log', (0.0,), ValueError), #cpython does it this way
- ('log1p', (-1.0,), OverflowError),
- ('log', (-1.,), ValueError),
- ('log10', (0.0,), ValueError), #cpython does it this way
- ]
-
- INFCASES = [
- ('acos', (INFINITY,), ValueError),
- ('acos', (-INFINITY,), ValueError),
- ('asin', (INFINITY,), ValueError),
- ('asin', (-INFINITY,), ValueError),
- ('atan', (INFINITY,), math.pi / 2),
- ('atan', (-INFINITY,), -math.pi / 2),
- ('atanh', (INFINITY,), ValueError),
- ('atanh', (-INFINITY,), ValueError),
- ('ceil', (INFINITY,), positiveinf),
- ('ceil', (-INFINITY,), negativeinf),
- ('cos', (INFINITY,), ValueError),
- ('cos', (-INFINITY,), ValueError),
- ('cosh', (INFINITY,), positiveinf),
- ('cosh', (-INFINITY,), positiveinf),
- ('exp', (INFINITY,), positiveinf),
- ('exp', (-INFINITY,), 0.0),
- ('fabs', (INFINITY,), positiveinf),
- ('fabs', (-INFINITY,), positiveinf),
- ('floor', (INFINITY,), positiveinf),
- ('floor', (-INFINITY,), negativeinf),
- ('sin', (INFINITY,), ValueError),
- ('sin', (-INFINITY,), ValueError),
- ('sinh', (INFINITY,), positiveinf),
- ('sinh', (-INFINITY,), negativeinf),
- ('sqrt', (INFINITY,), positiveinf),
- ('sqrt', (-INFINITY,), ValueError),
- ('tan', (INFINITY,), ValueError),
- ('tan', (-INFINITY,), ValueError),
- ('tanh', (INFINITY,), 1.0),
- ('tanh', (-INFINITY,), -1.0),
- ('log', (INFINITY,), positiveinf),
- ('log', (-INFINITY,), ValueError),
- ('log10', (INFINITY,), positiveinf),
- ('log10', (-INFINITY,), ValueError),
- ('frexp', (INFINITY,), lambda x: isinf(x[0])),
- ('ldexp', (INFINITY, 3), positiveinf),
- ('ldexp', (-INFINITY, 3), negativeinf),
- ('modf', (INFINITY,), lambda x: positiveinf(x[1])),
- ('modf', (-INFINITY,), lambda x: negativeinf(x[1])),
- ('pow', (INFINITY, 0.0), 1.0),
- ('pow', (INFINITY, 0.001), positiveinf),
- ('pow', (INFINITY, -0.001), 0.0),
- ('pow', (-INFINITY, 0.0), 1.0),
- ('pow', (-INFINITY, 0.001), positiveinf),
- ('pow', (-INFINITY, -0.001), 0.0),
- ('pow', (-INFINITY, 3.0), negativeinf),
- ('pow', (-INFINITY, 6.0), positiveinf),
- ('pow', (-INFINITY, -13.0), -0.0),
- ('pow', (-INFINITY, -128.0), 0.0),
- ('pow', (1.001, INFINITY), positiveinf),
- ('pow', (1.0, INFINITY), 1.0),
- ('pow', (0.999, INFINITY), 0.0),
- ('pow', (-0.999,INFINITY), 0.0),
- #('pow', (-1.0, INFINITY), 1.0, but strange, could also be -1.0),
- ('pow', (-1.001,INFINITY), positiveinf),
- ('pow', (1.001, -INFINITY), 0.0),
- ('pow', (1.0, -INFINITY), 1.0),
- #('pow', (0.999, -INFINITY), positiveinf, but get OverflowError),
- #('pow', (INFINITY, INFINITY), positiveinf, but get OverflowError),
- ('pow', (INFINITY, -INFINITY), 0.0),
- ('pow', (-INFINITY, INFINITY), positiveinf),
- ]
-
- IRREGERRCASES = [
- #
- ('atan2', (INFINITY, -2.3), math.pi / 2),
- ('atan2', (INFINITY, 0.0), math.pi / 2),
- ('atan2', (INFINITY, 3.0), math.pi / 2),
- #('atan2', (INFINITY, INFINITY), ?strange),
- ('atan2', (2.1, INFINITY), 0.0),
- ('atan2', (0.0, INFINITY), 0.0),
- ('atan2', (-0.1, INFINITY), -0.0),
- ('atan2', (-INFINITY, 0.4), -math.pi / 2),
- ('atan2', (2.1, -INFINITY), math.pi),
- ('atan2', (0.0, -INFINITY), math.pi),
- ('atan2', (-0.1, -INFINITY), -math.pi),
- #
- ('fmod', (INFINITY, 1.0), ValueError),
- ('fmod', (1.0, INFINITY), 1.0),
- ('fmod', (1.0, -INFINITY), 1.0),
- ('fmod', (INFINITY, INFINITY), ValueError),
- #
- ('hypot', (-INFINITY, 1.0), positiveinf),
- ('hypot', (-2.3, -INFINITY), positiveinf),
- ]
-
- binary_math_functions = ['atan2', 'fmod', 'hypot', 'pow']
-
- NANCASES1 = [
- (name, (NAN,), isnan) for name in unary_math_functions]
- NANCASES2 = [
- (name, (NAN, 0.1), isnan) for name in binary_math_functions]
- NANCASES3 = [
- (name, (-0.2, NAN), isnan) for name in binary_math_functions]
- NANCASES4 = [
- (name, (NAN, -INFINITY), isnan) for name in binary_math_functions
- if name != 'hypot']
- NANCASES5 = [
- (name, (INFINITY, NAN), isnan) for name in binary_math_functions
- if name != 'hypot']
- NANCASES6 = [
- ('frexp', (NAN,), lambda x: isnan(x[0])),
- ('ldexp', (NAN, 2), isnan),
- ('hypot', (NAN, INFINITY), positiveinf),
- ('hypot', (NAN, -INFINITY), positiveinf),
- ('hypot', (INFINITY, NAN), positiveinf),
- ('hypot', (-INFINITY, NAN), positiveinf),
- ('modf', (NAN,), lambda x: (isnan(x[0]) and isnan(x[1]))),
- ]
-
- # The list of test cases. Note that various tests import this,
- # notably in rpython/lltypesystem/module and in translator/c/test.
- TESTCASES = (REGCASES + IRREGCASES + OVFCASES + INFCASES + IRREGERRCASES
- + NANCASES1 + NANCASES2 + NANCASES3 + NANCASES4 + NANCASES5
- + NANCASES6)
-
-
class TestDirect(MathTests):
pass
-def get_tester(expected):
- if type(expected) is type(Exception):
- def tester(value):
- return False
- elif callable(expected):
- def tester(value):
- ok = expected(value)
- assert isinstance(ok, bool)
- return ok
- else:
- assert finite(expected), "badly written test"
- def tester(got):
- gotsign = expectedsign = 1
- if got < 0.0: gotsign = -gotsign
- if expected < 0.0: expectedsign = -expectedsign
- return finite(got) and (got == expected and
- gotsign == expectedsign)
- return tester
-
def do_test(fn, fnname, args, expected):
repr = "%s(%s)" % (fnname, ', '.join(map(str, args)))
try:
diff --git a/rpython/jit/backend/x86/test/test_zmath.py
b/rpython/jit/backend/x86/test/test_zmath.py
--- a/rpython/jit/backend/x86/test/test_zmath.py
+++ b/rpython/jit/backend/x86/test/test_zmath.py
@@ -2,13 +2,13 @@
compiled to C with SSE2 enabled.
"""
import py, math
-from pypy.module.math.test import test_direct
from rpython.translator.c.test.test_genc import compile
from rpython.jit.backend.x86.support import ensure_sse2_floats
from rpython.rlib import rfloat
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.debug import debug_print
-
+from rpython.rtyper.lltypesystem.module.test.test_ll_math import (MathTests,
+ getTester)
def get_test_case((fnname, args, expected)):
try:
@@ -17,7 +17,7 @@
fn = getattr(rfloat, fnname)
expect_valueerror = (expected == ValueError)
expect_overflowerror = (expected == OverflowError)
- check = test_direct.get_tester(expected)
+ check = get_tester(expected)
unroll_args = unrolling_iterable(args)
#
def testfn():
@@ -50,7 +50,7 @@
testfnlist = [get_test_case(testcase)
- for testcase in test_direct.MathTests.TESTCASES]
+ for testcase in MathTests.TESTCASES]
def fn():
ensure_sse2_floats()
@@ -64,6 +64,6 @@
f = compile(fn, [])
res = f()
if res >= 0:
- py.test.fail(repr(test_direct.MathTests.TESTCASES[res]))
+ py.test.fail(repr(MathTests.TESTCASES[res]))
else:
assert res == -42
diff --git a/rpython/jit/tool/pypytrace-mode.el
b/rpython/jit/tool/pypytrace-mode.el
--- a/rpython/jit/tool/pypytrace-mode.el
+++ b/rpython/jit/tool/pypytrace-mode.el
@@ -18,7 +18,7 @@
;; to generate the list of keywords:
-;; from pypy.jit.metainterp import resoperation
+;; from rpython.jit.metainterp import resoperation
;; print ' '.join(sorted('"%s"' % op.lower() for op in
resoperation.opname.values() if not op.startswith('GUARD')))
diff --git a/rpython/rtyper/lltypesystem/module/test/test_ll_math.py
b/rpython/rtyper/lltypesystem/module/test/test_ll_math.py
--- a/rpython/rtyper/lltypesystem/module/test/test_ll_math.py
+++ b/rpython/rtyper/lltypesystem/module/test/test_ll_math.py
@@ -2,10 +2,194 @@
"""
from rpython.rtyper.lltypesystem.module import ll_math
-from pypy.module.math.test.test_direct import MathTests, get_tester
from rpython.translator.c.test.test_genc import compile
+def positiveinf(x):
+ return isinf(x) and x > 0.0
+
+def negativeinf(x):
+ return isinf(x) and x < 0.0
+
+def finite(x):
+ return not isinf(x) and not isnan(x)
+
+
+unary_math_functions = ['acos', 'asin', 'atan',
+ 'ceil', 'cos', 'cosh', 'exp', 'fabs', 'floor',
+ 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'log', 'log10',
+ 'acosh', 'asinh', 'atanh', 'log1p', 'expm1']
+binary_math_functions = ['atan2', 'fmod', 'hypot', 'pow']
+
+class MathTests:
+
+ REGCASES = []
+ for name in unary_math_functions:
+ try:
+ input, output = (0.3,), getattr(math, name)(0.3)
+ except AttributeError:
+ # cannot test this function
+ continue
+ except ValueError:
+ input, output = (1.3,), getattr(math, name)(1.3)
+ REGCASES.append((name, input, output))
+
+ IRREGCASES = [
+ ('atan2', (0.31, 0.123), math.atan2(0.31, 0.123)),
+ ('fmod', (0.31, 0.123), math.fmod(0.31, 0.123)),
+ ('hypot', (0.31, 0.123), math.hypot(0.31, 0.123)),
+ ('pow', (0.31, 0.123), math.pow(0.31, 0.123)),
+ ('pow', (-0.31, 0.123), ValueError),
+ ('pow', (-0.5, 2.0), 0.25),
+ ('pow', (-0.5, 1.0), -0.5),
+ ('pow', (-0.5, 0.0), 1.0),
+ ('pow', (-0.5, -1.0), -2.0),
+ ('ldexp', (3.375, 2), 13.5),
+ ('ldexp', (1.0, -10000), 0.0), # underflow
+ ('frexp', (-1.25,), lambda x: x == (-0.625, 1)),
+ ('modf', (4.25,), lambda x: x == (0.25, 4.0)),
+ ('modf', (-4.25,), lambda x: x == (-0.25, -4.0)),
+ ('copysign', (1.5, 0.0), 1.5),
+ ('copysign', (1.5, -0.0), -1.5),
+ ('copysign', (1.5, INFINITY), 1.5),
+ ('copysign', (1.5, -INFINITY), -1.5),
+ ]
+ if sys.platform != 'win32': # all NaNs seem to be negative there...?
+ IRREGCASES += [
+ ('copysign', (1.5, NAN), 1.5),
+ ('copysign', (1.75, -NAN), -1.75), # special case for -NAN here
+ ]
+
+ OVFCASES = [
+ ('cosh', (9999.9,), OverflowError),
+ ('sinh', (9999.9,), OverflowError),
+ ('exp', (9999.9,), OverflowError),
+ ('pow', (10.0, 40000.0), OverflowError),
+ ('ldexp', (10.0, 40000), OverflowError),
+ ('log', (0.0,), ValueError), #cpython does it this way
+ ('log1p', (-1.0,), OverflowError),
+ ('log', (-1.,), ValueError),
+ ('log10', (0.0,), ValueError), #cpython does it this way
+ ]
+
+ INFCASES = [
+ ('acos', (INFINITY,), ValueError),
+ ('acos', (-INFINITY,), ValueError),
+ ('asin', (INFINITY,), ValueError),
+ ('asin', (-INFINITY,), ValueError),
+ ('atan', (INFINITY,), math.pi / 2),
+ ('atan', (-INFINITY,), -math.pi / 2),
+ ('atanh', (INFINITY,), ValueError),
+ ('atanh', (-INFINITY,), ValueError),
+ ('ceil', (INFINITY,), positiveinf),
+ ('ceil', (-INFINITY,), negativeinf),
+ ('cos', (INFINITY,), ValueError),
+ ('cos', (-INFINITY,), ValueError),
+ ('cosh', (INFINITY,), positiveinf),
+ ('cosh', (-INFINITY,), positiveinf),
+ ('exp', (INFINITY,), positiveinf),
+ ('exp', (-INFINITY,), 0.0),
+ ('fabs', (INFINITY,), positiveinf),
+ ('fabs', (-INFINITY,), positiveinf),
+ ('floor', (INFINITY,), positiveinf),
+ ('floor', (-INFINITY,), negativeinf),
+ ('sin', (INFINITY,), ValueError),
+ ('sin', (-INFINITY,), ValueError),
+ ('sinh', (INFINITY,), positiveinf),
+ ('sinh', (-INFINITY,), negativeinf),
+ ('sqrt', (INFINITY,), positiveinf),
+ ('sqrt', (-INFINITY,), ValueError),
+ ('tan', (INFINITY,), ValueError),
+ ('tan', (-INFINITY,), ValueError),
+ ('tanh', (INFINITY,), 1.0),
+ ('tanh', (-INFINITY,), -1.0),
+ ('log', (INFINITY,), positiveinf),
+ ('log', (-INFINITY,), ValueError),
+ ('log10', (INFINITY,), positiveinf),
+ ('log10', (-INFINITY,), ValueError),
+ ('frexp', (INFINITY,), lambda x: isinf(x[0])),
+ ('ldexp', (INFINITY, 3), positiveinf),
+ ('ldexp', (-INFINITY, 3), negativeinf),
+ ('modf', (INFINITY,), lambda x: positiveinf(x[1])),
+ ('modf', (-INFINITY,), lambda x: negativeinf(x[1])),
+ ('pow', (INFINITY, 0.0), 1.0),
+ ('pow', (INFINITY, 0.001), positiveinf),
+ ('pow', (INFINITY, -0.001), 0.0),
+ ('pow', (-INFINITY, 0.0), 1.0),
+ ('pow', (-INFINITY, 0.001), positiveinf),
+ ('pow', (-INFINITY, -0.001), 0.0),
+ ('pow', (-INFINITY, 3.0), negativeinf),
+ ('pow', (-INFINITY, 6.0), positiveinf),
+ ('pow', (-INFINITY, -13.0), -0.0),
+ ('pow', (-INFINITY, -128.0), 0.0),
+ ('pow', (1.001, INFINITY), positiveinf),
+ ('pow', (1.0, INFINITY), 1.0),
+ ('pow', (0.999, INFINITY), 0.0),
+ ('pow', (-0.999,INFINITY), 0.0),
+ #('pow', (-1.0, INFINITY), 1.0, but strange, could also be -1.0),
+ ('pow', (-1.001,INFINITY), positiveinf),
+ ('pow', (1.001, -INFINITY), 0.0),
+ ('pow', (1.0, -INFINITY), 1.0),
+ #('pow', (0.999, -INFINITY), positiveinf, but get OverflowError),
+ #('pow', (INFINITY, INFINITY), positiveinf, but get OverflowError),
+ ('pow', (INFINITY, -INFINITY), 0.0),
+ ('pow', (-INFINITY, INFINITY), positiveinf),
+ ]
+
+ IRREGERRCASES = [
+ #
+ ('atan2', (INFINITY, -2.3), math.pi / 2),
+ ('atan2', (INFINITY, 0.0), math.pi / 2),
+ ('atan2', (INFINITY, 3.0), math.pi / 2),
+ #('atan2', (INFINITY, INFINITY), ?strange),
+ ('atan2', (2.1, INFINITY), 0.0),
+ ('atan2', (0.0, INFINITY), 0.0),
+ ('atan2', (-0.1, INFINITY), -0.0),
+ ('atan2', (-INFINITY, 0.4), -math.pi / 2),
+ ('atan2', (2.1, -INFINITY), math.pi),
+ ('atan2', (0.0, -INFINITY), math.pi),
+ ('atan2', (-0.1, -INFINITY), -math.pi),
+ #
+ ('fmod', (INFINITY, 1.0), ValueError),
+ ('fmod', (1.0, INFINITY), 1.0),
+ ('fmod', (1.0, -INFINITY), 1.0),
+ ('fmod', (INFINITY, INFINITY), ValueError),
+ #
+ ('hypot', (-INFINITY, 1.0), positiveinf),
+ ('hypot', (-2.3, -INFINITY), positiveinf),
+ ]
+
+ binary_math_functions = ['atan2', 'fmod', 'hypot', 'pow']
+
+ NANCASES1 = [
+ (name, (NAN,), isnan) for name in unary_math_functions]
+ NANCASES2 = [
+ (name, (NAN, 0.1), isnan) for name in binary_math_functions]
+ NANCASES3 = [
+ (name, (-0.2, NAN), isnan) for name in binary_math_functions]
+ NANCASES4 = [
+ (name, (NAN, -INFINITY), isnan) for name in binary_math_functions
+ if name != 'hypot']
+ NANCASES5 = [
+ (name, (INFINITY, NAN), isnan) for name in binary_math_functions
+ if name != 'hypot']
+ NANCASES6 = [
+ ('frexp', (NAN,), lambda x: isnan(x[0])),
+ ('ldexp', (NAN, 2), isnan),
+ ('hypot', (NAN, INFINITY), positiveinf),
+ ('hypot', (NAN, -INFINITY), positiveinf),
+ ('hypot', (INFINITY, NAN), positiveinf),
+ ('hypot', (-INFINITY, NAN), positiveinf),
+ ('modf', (NAN,), lambda x: (isnan(x[0]) and isnan(x[1]))),
+ ]
+
+ # The list of test cases. Note that various tests import this,
+ # notably in rpython/lltypesystem/module and in translator/c/test.
+ TESTCASES = (REGCASES + IRREGCASES + OVFCASES + INFCASES + IRREGERRCASES
+ + NANCASES1 + NANCASES2 + NANCASES3 + NANCASES4 + NANCASES5
+ + NANCASES6)
+
+
class TestMath(MathTests):
def test_isinf(self):
inf = 1e200 * 1e200
@@ -68,6 +252,25 @@
assert not f(1e200, 1e200) # nan
+def get_tester(expected):
+ if type(expected) is type(Exception):
+ def tester(value):
+ return False
+ elif callable(expected):
+ def tester(value):
+ ok = expected(value)
+ assert isinstance(ok, bool)
+ return ok
+ else:
+ assert finite(expected), "badly written test"
+ def tester(got):
+ gotsign = expectedsign = 1
+ if got < 0.0: gotsign = -gotsign
+ if expected < 0.0: expectedsign = -expectedsign
+ return finite(got) and (got == expected and
+ gotsign == expectedsign)
+ return tester
+
from rpython.rtyper.lltypesystem import lltype
_A = lltype.GcArray(lltype.Float)
def normalize(x):
@@ -91,7 +294,7 @@
assert expected == OverflowError, "%s: got an OverflowError" % (
repr,)
else:
- if not get_tester(expected)(got):
+ if not (expected)(got):
raise AssertionError("%r: got %r, expected %r" %
(repr, got, expected))
#
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit