1 #define BOOST_TEST_MODULE (Product aggregation Test) 2 #include "boost/test/unit_test.hpp" 23 double constexpr
tolerance = std::numeric_limits<double>::epsilon();
25 struct HoursPerWorker {
27 : name_{name}, hours_{hours}
33 aggregate(HoursPerWorker
const&
b)
45 aggregate(
A const&)
const 55 operator<<(ostream& os, pair<string, unsigned>
const&
p)
57 os <<
'[' <<
p.first <<
',' <<
p.second <<
']';
62 operator<<(ostream& os, pair<cet::map_vector_key, string>
const&
entry)
69 BOOST_AUTO_TEST_SUITE(aggregate_t)
74 r1.
put<HoursPerWorker>(HoursPerWorker{
"Sam", 12});
75 r1.
put<HoursPerWorker>(HoursPerWorker{
"Sam", 14});
76 auto sam = r1.
get<HoursPerWorker>();
77 BOOST_TEST(sam.name_ ==
"Sam");
78 BOOST_TEST(sam.hours_ == 26u);
81 r2.
put<HoursPerWorker>(HoursPerWorker{
"John", 8});
82 r2.
put<HoursPerWorker>(HoursPerWorker{
"Jim", 10});
83 auto john = r2.
get<HoursPerWorker>();
84 BOOST_TEST(john.name_ ==
"John");
85 BOOST_TEST(john.hours_ == 8u);
93 BOOST_CHECK_CLOSE_FRACTION(r.
get<
double>(), 17.7,
tolerance);
98 using nums_t = std::vector<int>;
100 r.
put<nums_t>(nums_t{1, 3, 5});
101 r.
put<nums_t>(nums_t{2, 4, 6});
102 auto ref = {1, 3, 5, 2, 4, 6};
103 BOOST_TEST(r.
get<nums_t>() == ref, boost::test_tools::per_element{});
108 using chars_t = std::list<char>;
110 r.
put<chars_t>(chars_t{
'a',
'b',
'c'});
111 r.
put<chars_t>(chars_t{
'y',
'z'});
112 auto ref = {
'a',
'b',
'c',
'y',
'z'};
113 BOOST_TEST(r.
get<chars_t>() == ref, boost::test_tools::per_element{});
118 using nums_t = std::deque<unsigned>;
120 r.
put<nums_t>(nums_t{0, 5, 8});
121 r.
put<nums_t>(nums_t{1, 2, 4});
122 std::initializer_list<unsigned>
const ref{0u, 5u, 8u, 1u, 2u, 4u};
123 BOOST_TEST(r.
get<nums_t>() == ref, boost::test_tools::per_element{});
128 using histo_t = std::array<int, 3>;
130 r.
put<histo_t>(histo_t{{1, 4, 7}});
131 r.
put<histo_t>(histo_t{{-1, 6, 92}});
132 auto ref = {0, 10, 99};
133 BOOST_TEST(r.
get<histo_t>() == ref, boost::test_tools::per_element{});
138 using map_t = std::map<std::string, unsigned>;
139 map_t
const children{{
"Billy", 7}, {
"Josephine", 9}, {
"Gregory", 0}};
140 map_t
const adults{{
"Jennifer", 28}, {
"Gregory", 47}, {
"Ervin", 78}};
142 r.
put<map_t>(children);
143 r.
put<map_t>(adults);
144 map_t
const people{{
"Billy", 7},
149 BOOST_TEST(r.
get<map_t>() == people);
154 using map_t = std::multimap<std::string, unsigned>;
155 map_t
const children{{
"Billy", 7}, {
"Josephine", 9}, {
"Gregory", 0}};
156 map_t
const adults{{
"Jennifer", 28}, {
"Gregory", 47}, {
"Ervin", 78}};
158 r.
put<map_t>(children);
159 r.
put<map_t>(adults);
160 map_t
const people{{
"Billy", 7},
166 BOOST_TEST(r.
get<map_t>() == people);
171 using set_t = std::set<std::string>;
173 r.
put<set_t>(set_t{
"Brahms",
"Beethoven"});
174 r.
put<set_t>(set_t{
"Bach",
"Brahms"});
175 set_t
const composers{
"Bach",
"Beethoven",
"Brahms"};
176 BOOST_TEST(r.
get<set_t>() == composers);
181 using pair_t = std::pair<unsigned, double>;
183 r.
put<pair_t>(pair_t{0u, 14.});
184 r.
put<pair_t>(pair_t{6u, 20.});
186 BOOST_TEST(result.first == 6u);
187 BOOST_CHECK_CLOSE_FRACTION(result.second, 34.,
tolerance);
192 using tuple_t = std::tuple<A, unsigned, double>;
194 r.
put<tuple_t>(tuple_t{
"run1"s, 3, 1.2});
195 r.
put<tuple_t>(tuple_t{
"run2"s, 74, 2.9});
197 BOOST_TEST(std::get<A>(result).name_ ==
"run1");
198 BOOST_TEST(std::get<unsigned>(result) == 77u);
199 BOOST_CHECK_CLOSE_FRACTION(std::get<double>(result), 4.1,
tolerance);
205 using key_type =
typename mv_t::key_type;
207 primes.
insert({key_type{2},
"two"});
208 primes.insert({key_type{3},
"three"});
209 primes.insert({key_type{5},
"five"});
212 more_nums.insert({key_type{7},
"seven"});
213 more_nums.insert({key_type{11},
"eleven"});
214 more_nums.insert({key_type{13},
"thirteen"});
218 r.
put<mv_t>(more_nums);
221 ref.insert({key_type{2},
"two"});
222 ref.insert({key_type{3},
"three"});
223 ref.insert({key_type{5},
"five"});
224 ref.insert({key_type{7},
"seven"});
225 ref.insert({key_type{11},
"eleven"});
226 ref.insert({key_type{13},
"thirteen"});
228 BOOST_TEST(r.
get<mv_t>() == ref, boost::test_tools::per_element{});
236 BOOST_REQUIRE_EXCEPTION(
238 return e.categoryCode() == art::errors::ProductCannotBeAggregated;
250 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(class_type)
std::pair< iterator, bool > insert(value_type const &x)
QCollection::Item first()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
auto array(Array const &a)
Returns a manipulator which will print the specified array.