From fe201ca1a0b1234f18e3f194cf9e5599d8ce51fb Mon Sep 17 00:00:00 2001 From: ManifoldFR Date: Thu, 30 Nov 2023 19:04:28 +0100 Subject: [PATCH] [unittest] add unit tests for std::array --- unittest/CMakeLists.txt | 5 +++++ unittest/python/test_std_array.py | 13 +++++++++++++ unittest/std_array.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 unittest/python/test_std_array.py create mode 100644 unittest/std_array.cpp diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 7da4556f6..7737f07ed 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -38,6 +38,7 @@ if(NOT NUMPY_WITH_BROKEN_UFUNC_SUPPORT) add_lib_unit_test(user_type) endif() add_lib_unit_test(std_vector) +add_lib_unit_test(std_array) add_lib_unit_test(user_struct) function(config_bind_optional tagname opttype) @@ -110,6 +111,10 @@ add_python_unit_test("py-std-vector" "unittest/python/test_std_vector.py" "python;unittest") set_tests_properties("py-std-vector" PROPERTIES DEPENDS ${PYWRAP}) +add_python_unit_test("py-std-array" "unittest/python/test_std_array.py" + "python;unittest") +set_tests_properties("py-std-array" PROPERTIES DEPENDS ${PYWRAP}) + add_python_unit_test("py-user-struct" "unittest/python/test_user_struct.py" "python;unittest") set_tests_properties("py-user-struct" PROPERTIES DEPENDS ${PYWRAP}) diff --git a/unittest/python/test_std_array.py b/unittest/python/test_std_array.py new file mode 100644 index 000000000..d2a414462 --- /dev/null +++ b/unittest/python/test_std_array.py @@ -0,0 +1,13 @@ +import std_array + + +ints = std_array.get_arr_3_ints() +print(ints[0]) +print(ints[1]) +print(ints[2]) +print(ints.tolist()) + +vecs = std_array.get_arr_3_vecs() +print(vecs[0]) +print(vecs[1]) +print(vecs[2]) diff --git a/unittest/std_array.cpp b/unittest/std_array.cpp new file mode 100644 index 000000000..a662a28f1 --- /dev/null +++ b/unittest/std_array.cpp @@ -0,0 +1,28 @@ +/// @file +/// @copyright Copyright 2023 CNRS INRIA + +#include "eigenpy/std-array.hpp" + +using Eigen::VectorXd; + +std::array get_arr_3_ints() { return {1, 2, 3}; } + +std::array get_arr_3_vecs() { + std::array out; + out[0].setOnes(4); + out[1].setZero(2); + out[2].setRandom(10); + return out; +} + +BOOST_PYTHON_MODULE(std_array) { + using namespace eigenpy; + + enableEigenPy(); + + StdArrayPythonVisitor >::expose("StdArr3_int"); + exposeStdArrayEigenSpecificType("VectorXd"); + + bp::def("get_arr_3_ints", get_arr_3_ints); + bp::def("get_arr_3_vecs", get_arr_3_vecs); +}