extended test case
authorStefan Behnel <scoder@users.berlios.de>
Wed, 21 Oct 2009 10:09:05 +0000 (12:09 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 21 Oct 2009 10:09:05 +0000 (12:09 +0200)
tests/run/parallel_swap_assign_T425.pyx

index a5ff22ee4fc57c554f8184fdfa3e5d6cdaf7c22c..a337e935a410cddfb4006a38fc315d94968f0d1d 100644 (file)
@@ -1,20 +1,3 @@
-__doc__ = u"""
->>> swap(1,2)
-(2, 1)
-
->>> l = [1,2,3,4]
->>> swap_list_items(l, 1, 2)
->>> l
-[1, 3, 2, 4]
->>> swap_list_items(l, 3, 0)
->>> l
-[4, 3, 2, 1]
->>> swap_list_items(l, 0, 5)
-Traceback (most recent call last):
-IndexError: list index out of range
->>> l
-[4, 3, 2, 1]
-"""
 
 cimport cython
 
@@ -28,10 +11,53 @@ cimport cython
     "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=True]",
     )
 def swap(a,b):
+    """
+    >>> swap(1,2)
+    (2, 1)
+    """
     a,b = b,a
     return a,b
 
 
+@cython.test_assert_path_exists(
+    "//ParallelAssignmentNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode/NameNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=False]/NameNode",
+    )
+@cython.test_fail_if_path_exists(
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=True]",
+    )
+def swap5(a,b,c,d,e):
+    """
+    >>> swap5(1,2,3,4,5)
+    (5, 4, 3, 2, 1)
+    """
+    a,b,c,d,e = e,d,c,b,a
+    return a,b,c,d,e
+
+
+@cython.test_assert_path_exists(
+    "//ParallelAssignmentNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode/NameNode",
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=False]/NameNode",
+    )
+@cython.test_fail_if_path_exists(
+    "//ParallelAssignmentNode/SingleAssignmentNode//CoerceToTempNode[@use_managed_ref=True]",
+    )
+cdef bint c_swap_cmp5(a, b, c, d, e):
+    a,b,c,d,e = e,d,c,b,a
+    return a > b > c > d > e
+
+def swap_cmp5(a,b,c,d,e):
+    """
+    >>> swap_cmp5(1,2,3,4,5)
+    True
+    """
+    return c_swap_cmp5(a,b,c,d,e)
+
+
 @cython.test_assert_path_exists(
     "//ParallelAssignmentNode",
     "//ParallelAssignmentNode/SingleAssignmentNode",
@@ -56,6 +82,20 @@ def swap_py(a,b):
 #    "//ParallelAssignmentNode/SingleAssignmentNode//IndexNode[@use_managed_ref=True]",
     )
 def swap_list_items(list a, int i, int j):
+    """
+    >>> l = [1,2,3,4]
+    >>> swap_list_items(l, 1, 2)
+    >>> l
+    [1, 3, 2, 4]
+    >>> swap_list_items(l, 3, 0)
+    >>> l
+    [4, 3, 2, 1]
+    >>> swap_list_items(l, 0, 5)
+    Traceback (most recent call last):
+    IndexError: list index out of range
+    >>> l
+    [4, 3, 2, 1]
+    """
     a[i], a[j] = a[j], a[i]