stl vector test
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 15 Jan 2010 07:33:36 +0000 (23:33 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 15 Jan 2010 07:33:36 +0000 (23:33 -0800)
tests/run/cpp_stl_vector.pyx [new file with mode: 0644]

diff --git a/tests/run/cpp_stl_vector.pyx b/tests/run/cpp_stl_vector.pyx
new file mode 100644 (file)
index 0000000..cdcb71b
--- /dev/null
@@ -0,0 +1,39 @@
+cdef extern from "<vector>" namespace std:
+
+    cdef cppclass vector[T]:
+        void push_back(T)
+        size_t size()
+
+def simple_test(double x):
+    """
+    >>> simple_test(55)
+    3
+    """
+    cdef vector[double] *v 
+    try:
+        v = new vector[double]()
+        v.push_back(1.0)
+        v.push_back(x)
+        from math import pi
+        v.push_back(pi)
+        return v.size()
+    finally:
+        del v
+
+def list_test(L):
+    """
+    >>> list_test([1,2,4,8])
+    (4, 4)
+    >>> list_test([])
+    (0, 0)
+    >>> list_test([-1] * 1000)
+    (1000, 1000)
+    """
+    cdef vector[int] *v 
+    try:
+        v = new vector[int]()
+        for a in L:
+            v.push_back(a)
+        return len(L), v.size()
+    finally:
+        del v