Tests for ticket #445.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 31 Jan 2010 00:35:06 +0000 (16:35 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 31 Jan 2010 00:35:06 +0000 (16:35 -0800)
tests/run/complex_cast_T445.pyx [new file with mode: 0644]

diff --git a/tests/run/complex_cast_T445.pyx b/tests/run/complex_cast_T445.pyx
new file mode 100644 (file)
index 0000000..d64c685
--- /dev/null
@@ -0,0 +1,47 @@
+def complex_double_cast(double x, double complex z):
+    """
+    >>> complex_double_cast(1, 4-3j)
+    ((1+0j), (4-3j))
+    """
+    cdef double complex xx = <double complex>x
+    cdef double complex zz = <double complex>z
+    xx = x
+    return xx, zz
+
+def complex_double_int_cast(int x, int complex z):
+    """
+    >>> complex_double_int_cast(2, 2 + 3j)
+    ((2+0j), (3+3j))
+    """
+    cdef double complex xx = <double complex>x
+    cdef double complex zz = <double complex>(z+1)
+    return xx, zz
+
+def complex_int_double_cast(double x, double complex z):
+    """
+    >>> complex_int_double_cast(2.5, 2.5 + 3.5j)
+    ((2+0j), (2+3j))
+    """
+    cdef int complex xx = <int complex>x
+    cdef int complex zz = <int complex>z
+    return xx, zz
+
+cdef int side_effect_counter = 0
+
+cdef double complex side_effect(double complex z):
+    global side_effect_counter
+    side_effect_counter += 1
+    print "side effect", side_effect_counter, z
+    return z
+
+def test_side_effect(int complex z):
+    """
+    >>> test_side_effect(5)
+    side effect 1 (5+0j)
+    (5+0j)
+    >>> test_side_effect(3-4j)
+    side effect 2 (3-4j)
+    (3-4j)
+    """
+    cdef int complex zz = <int complex>side_effect(z)
+    return zz