extended test case
authorStefan Behnel <scoder@users.berlios.de>
Thu, 11 Feb 2010 21:21:27 +0000 (22:21 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 11 Feb 2010 21:21:27 +0000 (22:21 +0100)
tests/run/carray_slicing.pyx

index dedaf6765e17b1fdc6e2de78eb143f9fcbf2fd0c..c3b7868939bb9668ff39c46c845f88771110dc46 100644 (file)
@@ -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 ]