Macros | Functions
aggregate_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "MockRun.h"
#include "cetlib/map_vector.h"
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include <tuple>
#include <vector>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (Product aggregation Test)
 

Functions

ostream & std::operator<< (ostream &os, pair< string, unsigned > const &p)
 
ostream & std::operator<< (ostream &os, pair< cet::map_vector_key, string > const &entry)
 
 BOOST_AUTO_TEST_CASE (class_type)
 
 BOOST_AUTO_TEST_CASE (numbers)
 
 BOOST_AUTO_TEST_CASE (vector)
 
 BOOST_AUTO_TEST_CASE (list)
 
 BOOST_AUTO_TEST_CASE (deque)
 
 BOOST_AUTO_TEST_CASE (array)
 
 BOOST_AUTO_TEST_CASE (map)
 
 BOOST_AUTO_TEST_CASE (multimap)
 
 BOOST_AUTO_TEST_CASE (set)
 
 BOOST_AUTO_TEST_CASE (pair)
 
 BOOST_AUTO_TEST_CASE (tuple)
 
 BOOST_AUTO_TEST_CASE (map_vector)
 
 BOOST_AUTO_TEST_CASE (string1)
 
 BOOST_AUTO_TEST_CASE (string2)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (Product aggregation Test)

Definition at line 1 of file aggregate_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( class_type  )

Definition at line 71 of file aggregate_t.cc.

72 {
73  MockRun r1;
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);
79 
80  MockRun r2;
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);
86 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( numbers  )

Definition at line 88 of file aggregate_t.cc.

89 {
90  MockRun r;
91  r.put<double>(14.3);
92  r.put<double>(3.4);
93  BOOST_CHECK_CLOSE_FRACTION(r.get<double>(), 17.7, tolerance);
94 }
auto const tolerance
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( vector  )

Definition at line 96 of file aggregate_t.cc.

97 {
98  using nums_t = std::vector<int>;
99  MockRun r;
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{});
104 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( list  )

Definition at line 106 of file aggregate_t.cc.

107 {
108  using chars_t = std::list<char>;
109  MockRun r;
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{});
114 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( deque  )

Definition at line 116 of file aggregate_t.cc.

117 {
118  using nums_t = std::deque<unsigned>;
119  MockRun r;
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{});
124 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( array  )

Definition at line 126 of file aggregate_t.cc.

127 {
128  using histo_t = std::array<int, 3>;
129  MockRun r;
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{});
134 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( map  )

Definition at line 136 of file aggregate_t.cc.

137 {
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}};
141  MockRun r;
142  r.put<map_t>(children);
143  r.put<map_t>(adults);
144  map_t const people{{"Billy", 7},
145  {"Ervin", 78},
146  {"Gregory", 0},
147  {"Jennifer", 28},
148  {"Josephine", 9}};
149  BOOST_TEST(r.get<map_t>() == people);
150 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( multimap  )

Definition at line 152 of file aggregate_t.cc.

153 {
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}};
157  MockRun r;
158  r.put<map_t>(children);
159  r.put<map_t>(adults);
160  map_t const people{{"Billy", 7},
161  {"Ervin", 78},
162  {"Gregory", 0},
163  {"Gregory", 47},
164  {"Jennifer", 28},
165  {"Josephine", 9}};
166  BOOST_TEST(r.get<map_t>() == people);
167 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( set  )

Definition at line 169 of file aggregate_t.cc.

170 {
171  using set_t = std::set<std::string>;
172  MockRun r;
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);
177 }
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( pair  )

Definition at line 179 of file aggregate_t.cc.

180 {
181  using pair_t = std::pair<unsigned, double>;
182  MockRun r;
183  r.put<pair_t>(pair_t{0u, 14.});
184  r.put<pair_t>(pair_t{6u, 20.});
185  auto result = r.get<pair_t>();
186  BOOST_TEST(result.first == 6u);
187  BOOST_CHECK_CLOSE_FRACTION(result.second, 34., tolerance);
188 }
static QCString result
auto const tolerance
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( tuple  )

Definition at line 190 of file aggregate_t.cc.

191 {
192  using tuple_t = std::tuple<A, unsigned, double>;
193  MockRun r;
194  r.put<tuple_t>(tuple_t{"run1"s, 3, 1.2});
195  r.put<tuple_t>(tuple_t{"run2"s, 74, 2.9});
196  auto result = r.get<tuple_t>();
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);
200 }
static QCString result
auto const tolerance
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( map_vector  )

Definition at line 202 of file aggregate_t.cc.

203 {
204  using mv_t = cet::map_vector<std::string>;
205  using key_type = typename mv_t::key_type;
206  mv_t primes;
207  primes.insert({key_type{2}, "two"});
208  primes.insert({key_type{3}, "three"});
209  primes.insert({key_type{5}, "five"});
210 
211  mv_t more_nums;
212  more_nums.insert({key_type{7}, "seven"});
213  more_nums.insert({key_type{11}, "eleven"});
214  more_nums.insert({key_type{13}, "thirteen"});
215 
216  MockRun r;
217  r.put<mv_t>(primes);
218  r.put<mv_t>(more_nums);
219 
220  mv_t ref;
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"});
227 
228  BOOST_TEST(r.get<mv_t>() == ref, boost::test_tools::per_element{});
229 }
std::pair< iterator, bool > insert(value_type const &x)
Definition: map_vector.h:471
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( string1  )

Definition at line 231 of file aggregate_t.cc.

232 {
233  MockRun r;
234  r.put<std::string>("howdy");
235  r.put<std::string>("dowdy");
236  BOOST_REQUIRE_EXCEPTION(
237  r.get<std::string>(), art::Exception, [](art::Exception const& e) {
238  return e.categoryCode() == art::errors::ProductCannotBeAggregated;
239  });
240 }
std::string string
Definition: nybbler.cc:12
const double e
T get() const
Definition: MockRun.h:24
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void put(ARGS &&...args)
Definition: MockRun.h:16
BOOST_AUTO_TEST_CASE ( string2  )

Definition at line 242 of file aggregate_t.cc.

243 {
244  MockRun r;
245  r.put<std::string>("howdy");
246  r.put<std::string>("howdy");
247  BOOST_TEST(r.get<std::string>() == "howdy");
248 }
std::string string
Definition: nybbler.cc:12
T get() const
Definition: MockRun.h:24
void put(ARGS &&...args)
Definition: MockRun.h:16
ostream& std::operator<< ( ostream &  os,
pair< string, unsigned > const &  p 
)

Definition at line 55 of file aggregate_t.cc.

56  {
57  os << '[' << p.first << ',' << p.second << ']';
58  return os;
59  }
p
Definition: test.py:223
ostream& std::operator<< ( ostream &  os,
pair< cet::map_vector_key, string > const &  entry 
)

Definition at line 62 of file aggregate_t.cc.

63  {
64  os << '[' << entry.first.asUint() << ',' << entry.second << ']';
65  return os;
66  }
QList< Entry > entry
QCollection::Item first()
Definition: qglist.cpp:807