Unit test for util::span
class.
More...
#include <boost/test/unit_test.hpp>
#include <boost/iterator/indirect_iterator.hpp>
#include "larcorealg/CoreUtils/span.h"
#include "larcorealg/CoreUtils/enumerate.h"
#include "larcorealg/CoreUtils/zip.h"
#include "larcorealg/CoreUtils/counter.h"
#include "larcorealg/CoreUtils/operations.h"
#include <iostream>
#include <vector>
#include <memory>
#include <numeric>
#include <type_traits>
Go to the source code of this file.
Unit test for util::span
class.
- Author
- Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
- Date
- January 29, 2019
- See Also
larcorealg/CoreUtils/span.h
Definition in file span_test.cc.
#define BOOST_TEST_MODULE ( RealComparisons_test ) |
BOOST_AUTO_TEST_CASE |
( |
span_testcase |
| ) |
|
Definition at line 372 of file span_test.cc.
374 using TestVector_t = std::vector<int>;
377 test_span<TestVector_t::iterator>(ev);
378 test_const_span<TestVector_t::const_iterator>(ev);
380 TestVector_t v3 { 1, 2, 3 };
381 test_span<TestVector_t::iterator>(v3);
382 test_const_span<TestVector_t::const_iterator>(v3);
384 TestVector_t
const cv4 { 1, 2, 3, 4 };
385 test_span<TestVector_t::const_iterator>(cv4);
386 test_const_span<TestVector_t::const_iterator>(cv4);
BOOST_AUTO_TEST_CASE |
( |
adapted_span_testcase |
| ) |
|
Definition at line 393 of file span_test.cc.
395 using TestVector_t = std::vector<int>;
398 test_adapted_span<TestVector_t::iterator>(ev);
400 TestVector_t v3 { 1, 2, 3 };
401 test_adapted_span<TestVector_t::iterator>(v3);
403 TestVector_t
const cv4 { 1, 2, 3, 4 };
404 test_adapted_span<TestVector_t::const_iterator>(cv4);
BOOST_AUTO_TEST_CASE |
( |
transformed_span_testcase |
| ) |
|
Definition at line 410 of file span_test.cc.
412 using TestVector_t = std::vector<int>;
415 test_transformed_span<TestVector_t::iterator>(ev);
416 test_transformed_span_with_unmoveable_values<TestVector_t::iterator>(ev);
418 TestVector_t v3 { 1, 2, 3 };
419 test_transformed_span<TestVector_t::iterator>(v3);
421 TestVector_t
const cv4 { 1, 2, 3, 4 };
422 test_transformed_span<TestVector_t::const_iterator>(cv4);
BOOST_AUTO_TEST_CASE |
( |
span_documentation_testcase |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
adapted_span_documentation_testcase |
| ) |
|
BOOST_AUTO_TEST_CASE |
( |
transformed_span_documentation_testcase |
| ) |
|
template<typename Iter , typename Cont >
void test_adapted_span |
( |
Cont & |
v | ) |
|
Definition at line 99 of file span_test.cc.
107 std::vector<typename Iter::pointer> ptrs;
109 (v.begin(), v.end(), std::back_inserter(ptrs), [](
auto& v){
return &v; });
112 (ptrs, [](
auto&& iter){
return boost::make_indirect_iterator(iter); });
116 std::is_same<
typename decltype(r)::value_type,
typename Iter::value_type>()
119 BOOST_TEST(r.empty() == v.empty());
120 BOOST_TEST(r.size() == v.size());
124 BOOST_TEST(&rangeValue == &
value);
125 BOOST_TEST(rangeValue ==
value);
128 BOOST_TEST(n == v.size());
auto make_adapted_span(BIter begin, EIter end, Adaptor &&adaptor)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
template<typename Iter , typename Cont >
void test_const_span |
( |
Cont & |
v | ) |
|
Definition at line 65 of file span_test.cc.
74 std::is_same<
typename decltype(
r)::value_type,
typename Iter::value_type>()
77 (std::is_same<
typename decltype(
r)::reference,
typename Iter::reference>());
79 BOOST_TEST((
r.begin() == v.cbegin()));
80 BOOST_TEST((
r.end() == v.cend()));
82 BOOST_TEST(
r.empty() == v.empty());
83 BOOST_TEST(
r.size() == v.size());
92 BOOST_TEST(n == v.size());
auto make_const_span(Cont &cont)
Creates a span with constant iterator access from a container type.
template<typename Iter , typename Cont >
void test_span |
( |
Cont & |
v | ) |
|
Definition at line 31 of file span_test.cc.
40 std::is_same<
typename decltype(
r)::value_type,
typename Iter::value_type>()
43 (std::is_same<
typename decltype(
r)::reference,
typename Iter::reference>());
45 BOOST_TEST((
r.begin() == v.begin()));
46 BOOST_TEST((
r.end() == v.end()));
48 BOOST_TEST(
r.empty() == v.empty());
49 BOOST_TEST(
r.size() == v.size());
58 BOOST_TEST(n == v.size());
auto make_span(BIter begin, EIter end)
Creates a span from specified iterators (can use constructor instead).
template<typename Iter , typename Cont >
void test_transformed_span |
( |
Cont & |
v | ) |
|
Definition at line 135 of file span_test.cc.
144 using pointer_t =
typename std::iterator_traits<Iter>::pointer;
145 using reference_t =
typename std::iterator_traits<Iter>::reference;
147 std::vector<pointer_t> ptrs;
149 (v.begin(), v.end(), std::back_inserter(ptrs), [](
auto& v){
return &v; });
152 (ptrs, [](
auto* ptr) ->
reference_t {
return *ptr; });
156 std::is_same<
typename decltype(r)::value_type,
typename Iter::value_type>()
159 BOOST_TEST(r.empty() == v.empty());
160 BOOST_TEST(r.size() == v.size());
164 BOOST_TEST(&rangeValue == &
value);
165 BOOST_TEST(rangeValue ==
value);
168 BOOST_TEST(n == v.size());
typename T::pointer pointer_t
auto make_transformed_span(BIter begin, EIter end, Op &&op)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
typename T::reference reference_t
template<typename Iter , typename Cont >
void test_transformed_span_with_unmoveable_values |
( |
Cont & |
v | ) |
|
Definition at line 175 of file span_test.cc.
184 using value_t =
typename std::iterator_traits<Iter>::value_type;
185 using pointer_t = std::unique_ptr<value_t>;
187 std::vector<pointer_t> ptrs;
189 v.begin(), v.end(), std::back_inserter(ptrs),
190 [](
auto& v){
return std::make_unique<value_t>(v); }
196 static_assert(std::is_same<
typename decltype(r)::value_type,
value_t>());
198 BOOST_TEST(r.empty() == v.empty());
199 BOOST_TEST(r.size() == v.size());
203 BOOST_TEST(&rangeValue == &
value);
204 BOOST_TEST(rangeValue ==
value);
207 BOOST_TEST(n == v.size());
typename T::pointer pointer_t
value_t
the JSON type enumeration
auto make_transformed_span(BIter begin, EIter end, Op &&op)
decltype(auto) dereference()
Returns a functor that returns *ptr of its argument ptr.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.