From ca354aabf9219c5adf888e4c99ef6f5129e515e4 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 11 Feb 2010 22:21:27 +0100 Subject: [PATCH] extended test case --- tests/run/carray_slicing.pyx | 60 +++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/tests/run/carray_slicing.pyx b/tests/run/carray_slicing.pyx index dedaf676..c3b78689 100644 --- a/tests/run/carray_slicing.pyx +++ b/tests/run/carray_slicing.pyx @@ -118,9 +118,9 @@ for i in range(6): @cython.test_assert_path_exists("//ForFromStatNode", "//ForFromStatNode//IndexNode") @cython.test_fail_if_path_exists("//ForInStatNode") -def slice_intptr_for_loop_c(): +def slice_intarray_for_loop_c(): """ - >>> slice_intptr_for_loop_c() + >>> slice_intarray_for_loop_c() [0, 1, 2] [1, 2, 3, 4] [4, 5] @@ -133,10 +133,62 @@ def slice_intptr_for_loop_c(): @cython.test_assert_path_exists("//ForFromStatNode", "//ForFromStatNode//IndexNode") @cython.test_fail_if_path_exists("//ForInStatNode") -def iter_intptr_for_loop_c(): +def iter_intarray_for_loop_c(): """ - >>> iter_intptr_for_loop_c() + >>> iter_intarray_for_loop_c() [0, 1, 2, 3, 4, 5] """ cdef int i print [ i for i in cints ] + +@cython.test_assert_path_exists("//ForFromStatNode", + "//ForFromStatNode//IndexNode") +@cython.test_fail_if_path_exists("//ForInStatNode") +def slice_intptr_for_loop_c(): + """ + >>> slice_intptr_for_loop_c() + [0, 1, 2] + [1, 2, 3, 4] + [4, 5] + """ + cdef int* nums = cints + cdef int i + print [ i for i in nums[:3] ] + print [ i for i in nums[1:5] ] + print [ i for i in nums[4:6] ] + + +############################################################ +# tests for slicing other arrays + +cdef double cdoubles[6] +for i in range(6): + cdoubles[i] = i + 0.1 + +cdef double* cdoubles_ptr = cdoubles + +@cython.test_assert_path_exists("//ForFromStatNode", + "//ForFromStatNode//IndexNode") +@cython.test_fail_if_path_exists("//ForInStatNode") +def slice_doublptr_for_loop_c(): + """ + >>> slice_doublptr_for_loop_c() + [0.1, 1.1, 2.1] + [1.1, 2.1, 3.1, 4.1] + [4.1, 5.1] + """ + cdef double d + print [ d for d in cdoubles_ptr[:3] ] + print [ d for d in cdoubles_ptr[1:5] ] + print [ d for d in cdoubles_ptr[4:6] ] + +@cython.test_assert_path_exists("//ForFromStatNode", + "//ForFromStatNode//IndexNode") +@cython.test_fail_if_path_exists("//ForInStatNode") +def iter_doublearray_for_loop_c(): + """ + >>> iter_doublearray_for_loop_c() + [0.1, 1.1, 2.1, 3.1, 4.1, 5.1] + """ + cdef double d + print [ d for d in cdoubles ] -- 2.26.2