More overflow testing.
authorRobert Bradshaw <robertwb@gmail.com>
Fri, 28 Dec 2012 20:27:12 +0000 (12:27 -0800)
committerRobert Bradshaw <robertwb@gmail.com>
Fri, 28 Dec 2012 20:27:12 +0000 (12:27 -0800)
tests/run/overflow_check.pxi
tests/run/overflow_check_int.pyx
tests/run/overflow_check_longlong.pyx
tests/run/overflow_check_uint.pyx
tests/run/overflow_check_ulonglong.pyx

index e28ffde..3603f95 100644 (file)
@@ -106,12 +106,12 @@ def test_mul(INT a, INT b):
     return int(a * b)
 
 @cython.overflowcheck(True)
-def test_nested(INT a, INT b, INT c):
+def test_nested_add(INT a, INT b, INT c):
     """
-    >>> test_nested(1, 2, 3)
+    >>> test_nested_add(1, 2, 3)
     6
-    >>> expect_overflow(test_nested, half + 1, half + 1, half + 1)
-    >>> expect_overflow(test_nested, half - 1, half - 1, half - 1)
+    >>> expect_overflow(test_nested_add, half + 1, half + 1, half + 1)
+    >>> expect_overflow(test_nested_add, half - 1, half - 1, half - 1)
     """
     return int(a + b + c)
 
@@ -155,6 +155,25 @@ cdef INT called(INT value):
     return value
 
 @cython.overflowcheck(True)
+def test_nested(INT a, INT b, INT c, INT d):
+    """
+    >>> test_nested_func(1, 2, 3)
+    called(5)
+    6
+    >>> expect_overflow(test_nested, half, half, 1, 1)
+    >>> expect_overflow(test_nested, half, 1, half, half)
+    >>> expect_overflow(test_nested, half, 2, half, 2)
+
+    >>> print(format(test_nested(half, 2, 0, 1)))
+    half + half - 0
+    >>> print(format(test_nested(1, 0, half, 2)))
+    half + half - 0
+    >>> print(format(test_nested(half, 1, 1, half)))
+    half + half - 0
+    """
+    return int(a * b + c * d)
+
+@cython.overflowcheck(True)
 def test_nested_func(INT a, INT b, INT c):
     """
     >>> test_nested_func(1, 2, 3)
@@ -166,7 +185,6 @@ def test_nested_func(INT a, INT b, INT c):
     >>> print(format(test_nested_func(1, half - 1, half - 1)))
     called(half + half - 2)
     half + half - 1
-    >>> 
     """
     return int(a + called(b + c))
 
index 6e8fcf0..51d4056 100644 (file)
@@ -1,3 +1,6 @@
+# cython: overflowcheck.fold = True
+
+
 ctypedef int INT
 
 include "overflow_check.pxi"
index ae7d779..3c5f5f1 100644 (file)
@@ -1,3 +1,6 @@
+# cython: overflowcheck.fold = False
+
+
 ctypedef long long INT
 
 include "overflow_check.pxi"
index e6f1bf1..1619695 100644 (file)
@@ -1,3 +1,6 @@
+# cython: overflowcheck.fold = False
+
+
 ctypedef unsigned int INT
 
 include "overflow_check.pxi"
index a4d11d7..958a58b 100644 (file)
@@ -1,3 +1,6 @@
+# cython: overflowcheck.fold = True
+
+
 ctypedef unsigned long long INT
 
 include "overflow_check.pxi"