Test of util::get_elements()
.
More...
#include "larcorealg/CoreUtils/get_elements.h"
#include "larcorealg/CoreUtils/zip.h"
#include <boost/test/unit_test.hpp>
#include <vector>
#include <tuple>
#include <utility>
#include <cstddef>
Go to the source code of this file.
#define BOOST_TEST_MODULE ( get_elements_test ) |
BOOST_AUTO_TEST_CASE |
( |
get_elements_testcase |
| ) |
|
Definition at line 259 of file get_elements_test.cc.
void test_get_const_elements_single()
void test_get_elements_single()
void test_get_const_elements()
void get_elements_documentation_test()
void get_elements_documentation_test |
( |
| ) |
|
Definition at line 198 of file get_elements_test.cc.
221 std::vector<std::tuple<char, int, float>>
data 222 { {
'z', 0, 1.0F }, {
'o', 1, 3.0F }, {
't', 2, 9.0F } };
223 std::map<char, double> factors;
225 for (
auto const& [ letter, factor ]: util::get_elements<0U, 2U>(
data)) {
226 factors.emplace(letter, factor);
229 std::vector<int> exponents;
231 for (
int exponent: util::get_elements<1U>(
data)) {
232 exponents.push_back(exponent);
238 std::map<char, double>
const expected_factors
239 { {
'z', 1.0F }, {
'o', 3.0F }, {
't', 9.0F } };
240 std::vector<int>
const expected_exponents{ 0, 1, 2 };
242 BOOST_TEST(factors.size() == expected_factors.size());
243 for (
auto const& [
f, expected_f ]:
util::zip(factors, expected_factors)) {
244 BOOST_TEST(
f.first == expected_f.first);
245 BOOST_TEST(
f.second == expected_f.second);
248 BOOST_CHECK_EQUAL_COLLECTIONS(
249 exponents.cbegin(), exponents.cend(),
250 expected_exponents.begin(), expected_exponents.end()
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
void test_get_const_elements |
( |
| ) |
|
Definition at line 71 of file get_elements_test.cc.
75 std::vector<std::tuple<int, void const*, A>>
const data {
84 auto iItem =
data.cbegin();
85 for (
auto&& [
index,
a ]: util::get_elements<0U, 2U>(std::as_const(
data))) {
86 static_assert(std::is_same_v<decltype(
index),
int const&>);
87 static_assert(std::is_same_v<decltype(
a),
A const&>);
88 BOOST_TEST(
index == std::get<0U>(*iItem));
89 BOOST_TEST(&
index == &std::get<0U>(*iItem));
90 BOOST_TEST(&
a == &std::get<2U>(*iItem));
93 BOOST_TEST((iItem ==
data.cend()));
100 auto iItem =
data.cbegin();
101 for (
auto&& [
index,
a ]: util::get_elements<0U, 2U>(
data)) {
102 static_assert(std::is_same_v<decltype(
index),
int const&>);
103 static_assert(std::is_same_v<decltype(
a),
A const&>);
104 BOOST_TEST(
index == std::get<0U>(*iItem));
105 BOOST_TEST(&
index == &std::get<0U>(*iItem));
106 BOOST_TEST(&
a == &std::get<2U>(*iItem));
109 BOOST_TEST((iItem ==
data.cend()));
void test_get_const_elements_single |
( |
| ) |
|
Definition at line 157 of file get_elements_test.cc.
161 std::vector<std::tuple<int, void const*, A>>
const data {
170 auto iItem =
data.cbegin();
171 for (
auto&&
index: util::get_elements<0U>(std::as_const(
data))) {
172 static_assert(std::is_same_v<decltype(
index),
int const&>);
173 BOOST_TEST(
index == std::get<0U>(*iItem));
174 BOOST_TEST(&
index == &std::get<0U>(*iItem));
177 BOOST_TEST((iItem ==
data.cend()));
184 auto iItem =
data.cbegin();
185 for (
auto&&
index: util::get_elements<0U>(
data)) {
186 static_assert(std::is_same_v<decltype(
index),
int const&>);
187 BOOST_TEST(
index == std::get<0U>(*iItem));
188 BOOST_TEST(&
index == &std::get<0U>(*iItem));
191 BOOST_TEST((iItem ==
data.cend()));
void test_get_elements |
( |
| ) |
|
Definition at line 27 of file get_elements_test.cc.
31 std::vector<std::tuple<int, void const*, A>>
data {
40 auto iItem =
data.cbegin();
41 for (
auto&& [
index,
a ]: util::get_elements<0U, 2U>(std::as_const(
data))) {
42 static_assert(std::is_same_v<decltype(
index),
int const&>);
43 static_assert(std::is_same_v<decltype(
a),
A const&>);
44 BOOST_TEST(
index == std::get<0U>(*iItem));
45 BOOST_TEST(&
index == &std::get<0U>(*iItem));
46 BOOST_TEST(&
a == &std::get<2U>(*iItem));
49 BOOST_TEST((iItem ==
data.cend()));
56 auto iItem =
data.cbegin();
57 for (
auto&& [
index,
a ]: util::get_elements<0U, 2U>(
data)) {
58 static_assert(std::is_same_v<decltype(
index),
int&>);
59 static_assert(std::is_same_v<decltype(
a),
A&>);
60 BOOST_TEST(
index == std::get<0U>(*iItem));
61 BOOST_TEST(&
index == &std::get<0U>(*iItem));
62 BOOST_TEST(&
a == &std::get<2U>(*iItem));
65 BOOST_TEST((iItem ==
data.cend()));
void test_get_elements_single |
( |
| ) |
|
Definition at line 117 of file get_elements_test.cc.
121 std::vector<std::tuple<int, void const*, A>>
data {
130 auto iItem =
data.cbegin();
131 for (
auto&&
index: util::get_elements<0U>(std::as_const(
data))) {
132 static_assert(std::is_same_v<decltype(
index),
int const&>);
133 BOOST_TEST(
index == std::get<0U>(*iItem));
134 BOOST_TEST(&
index == &std::get<0U>(*iItem));
137 BOOST_TEST((iItem ==
data.cend()));
144 auto iItem =
data.cbegin();
145 for (
auto&&
index: util::get_elements<0U>(
data)) {
146 static_assert(std::is_same_v<decltype(
index),
int&>);
147 BOOST_TEST(
index == std::get<0U>(*iItem));
148 BOOST_TEST(&
index == &std::get<0U>(*iItem));
151 BOOST_TEST((iItem ==
data.cend()));