Skip to content

Commit

Permalink
[unittest] add unit tests for std::array
Browse files Browse the repository at this point in the history
  • Loading branch information
ManifoldFR committed Nov 30, 2023
1 parent ad2fa27 commit fe201ca
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
13 changes: 13 additions & 0 deletions unittest/python/test_std_array.py
Original file line number Diff line number Diff line change
@@ -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])
28 changes: 28 additions & 0 deletions unittest/std_array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// @file
/// @copyright Copyright 2023 CNRS INRIA

#include "eigenpy/std-array.hpp"

using Eigen::VectorXd;

std::array<int, 3> get_arr_3_ints() { return {1, 2, 3}; }

std::array<VectorXd, 3> get_arr_3_vecs() {
std::array<VectorXd, 3> 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<std::array<int, 3> >::expose("StdArr3_int");
exposeStdArrayEigenSpecificType<VectorXd, 3>("VectorXd");

bp::def("get_arr_3_ints", get_arr_3_ints);
bp::def("get_arr_3_vecs", get_arr_3_vecs);
}

0 comments on commit fe201ca

Please sign in to comment.