From: Robert Bradshaw Date: Fri, 15 Jan 2010 07:33:36 +0000 (-0800) Subject: stl vector test X-Git-Tag: 0.13.beta0~353^2~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=58955c26341dbc323c28370509860ed7d584a4e4;p=cython.git stl vector test --- diff --git a/tests/run/cpp_stl_vector.pyx b/tests/run/cpp_stl_vector.pyx new file mode 100644 index 00000000..cdcb71ba --- /dev/null +++ b/tests/run/cpp_stl_vector.pyx @@ -0,0 +1,39 @@ +cdef extern from "" 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