Skip to content

Commit 3847cc4

Browse files
committed
test: add test for std::pair
1 parent 707613b commit 3847cc4

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

unittest/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if(NOT NUMPY_WITH_BROKEN_UFUNC_SUPPORT)
3939
endif()
4040
add_lib_unit_test(std_vector)
4141
add_lib_unit_test(std_array)
42+
add_lib_unit_test(std_pair)
4243
add_lib_unit_test(user_struct)
4344

4445
function(config_bind_optional tagname opttype)
@@ -115,6 +116,10 @@ add_python_unit_test("py-std-array" "unittest/python/test_std_array.py"
115116
"python;unittest")
116117
set_tests_properties("py-std-array" PROPERTIES DEPENDS ${PYWRAP})
117118

119+
add_python_unit_test("py-std-pair" "unittest/python/test_std_pair.py"
120+
"python;unittest")
121+
set_tests_properties("py-std-pair" PROPERTIES DEPENDS ${PYWRAP})
122+
118123
add_python_unit_test("py-user-struct" "unittest/python/test_user_struct.py"
119124
"python;unittest")
120125
set_tests_properties("py-user-struct" PROPERTIES DEPENDS ${PYWRAP})

unittest/python/test_std_pair.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from std_pair import std_pair_to_tuple
2+
3+
t = (1, 2.0)
4+
assert std_pair_to_tuple(t) == t

unittest/std_pair.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// @file
2+
/// @copyright Copyright 2023 CNRS INRIA
3+
4+
#include <eigenpy/eigenpy.hpp>
5+
#include <eigenpy/std-pair.hpp>
6+
#include <iostream>
7+
8+
namespace bp = boost::python;
9+
10+
template <typename T1, typename T2>
11+
bp::tuple std_pair_to_tuple(const std::pair<T1, T2>& pair) {
12+
return bp::make_tuple(pair.first, pair.second);
13+
}
14+
15+
BOOST_PYTHON_MODULE(std_pair) {
16+
using namespace eigenpy;
17+
18+
enableEigenPy();
19+
20+
typedef std::pair<int, double> PairType;
21+
StdPairConverter<PairType>::registration();
22+
23+
bp::def("std_pair_to_tuple", std_pair_to_tuple<int, double>);
24+
}

0 commit comments

Comments
 (0)