Commit f2a2f905 authored by Stefan Behnel's avatar Stefan Behnel

extended test case

parent 9f118eb6
__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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment