From f2a2f905978a6df8070a5f691a8177823b497889 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 21 Oct 2009 12:09:05 +0200 Subject: [PATCH] extended test case --- tests/run/parallel_swap_assign_T425.pyx | 74 +++++++++++++++++++------ 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/tests/run/parallel_swap_assign_T425.pyx b/tests/run/parallel_swap_assign_T425.pyx index a5ff22ee..a337e935 100644 --- a/tests/run/parallel_swap_assign_T425.pyx +++ b/tests/run/parallel_swap_assign_T425.pyx @@ -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] -- 2.26.2