From 58955c26341dbc323c28370509860ed7d584a4e4 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 14 Jan 2010 23:33:36 -0800 Subject: [PATCH] stl vector test --- tests/run/cpp_stl_vector.pyx | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/run/cpp_stl_vector.pyx 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 -- 2.26.2