tupleAs_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test tupleAs
4 //
5 // ======================================================================
6 
7 #define BOOST_TEST_MODULE (tupleAs test)
8 
9 #include "boost/test/unit_test.hpp"
10 
11 #include "FixtureBase.h"
14 #include "fhiclcpp/types/TupleAs.h"
15 
16 #include <string>
17 #include <vector>
18 
19 using namespace fhicl;
20 using namespace std;
21 
22 namespace {
23 
24  struct ThreeNumbers {
25  int i_, j_, k_;
26  ThreeNumbers(int i, int j, int k) : i_{i}, j_{j}, k_{k} {}
27  };
28 
29  struct Person {
30 
31  string name_;
32  unsigned age_{};
33 
34  Person() = default;
35  Person(string name, unsigned age) : name_{name}, age_{age} {}
36 
37  bool
38  operator==(Person const& p) const
39  {
40  return (name_ == p.name_) && (age_ == p.age_);
41  }
42 
43  bool
44  operator!=(Person const& p) const
45  {
46  return !operator==(p);
47  }
48  };
49 
50  ostream&
51  operator<<(ostream& os, Person const& p)
52  {
53  return os << "Name: " << p.name_ << " Age: " << p.age_;
54  }
55 
56  struct ToVector {
57 
58  ToVector(int j, vector<int> const& v)
59  {
60  for (auto number : v)
61  value_.push_back(j * number);
62  }
63 
64  vector<int> value_;
65  };
66 
67  struct Config {
69  Comment("Vector for Geant")};
71  ThreeNumbers{1, 3, 5}};
73  TupleAs<Person(string, unsigned)> person2{Name("person2"),
74  Person{"Jon", 97}};
78  Name("kids"),
79  std::vector<Person>{{"Billy", 10}, {"Susie", 14}}};
80  };
81 
82  struct Fixture : fhiclcpp_types::FixtureBase<Config> {
83  Fixture() : FixtureBase("tupleAs_t.fcl") {}
84  };
85 }
86 // provide use of 'Table<Config> config'
87 
88 BOOST_FIXTURE_TEST_SUITE(tupleAs_test, Fixture)
89 
90 BOOST_AUTO_TEST_CASE(tupleAs_simple)
91 {
92  ThreeNumbers const& tn1 = config().tn1();
93  BOOST_TEST(tn1.i_ == 1);
94  BOOST_TEST(tn1.j_ == 9);
95  BOOST_TEST(tn1.k_ == 17);
96 }
97 
98 BOOST_AUTO_TEST_CASE(tupleAs_default_value)
99 {
100  ThreeNumbers const& tn2 = config().tn2();
101  BOOST_TEST(tn2.i_ == 1);
102  BOOST_TEST(tn2.j_ == 3);
103  BOOST_TEST(tn2.k_ == 5);
104 }
105 
106 BOOST_AUTO_TEST_CASE(tupleAs_toVector)
107 {
108  ToVector const& v = config().toVector();
109  auto const ref = {5, 10, 15, 20};
110  BOOST_TEST(v.value_ == ref, boost::test_tools::per_element{});
111 }
112 
113 BOOST_AUTO_TEST_CASE(tupleAs_inSequence)
114 {
115  auto const& people = config().people();
116  auto const ref = {Person{"Alice", 1},
117  Person{"Bob", 2},
118  Person{"Charlie", 3},
119  Person{"Danielle", 4},
120  Person{"Edgar", 5}};
121  BOOST_TEST(people == ref, boost::test_tools::per_element{});
122 }
123 
124 BOOST_AUTO_TEST_CASE(tupleAs_inSequence_2)
125 {
126  auto const& people = config().kids();
127  auto const ref = {Person{"Billy", 10}, Person{"Susie", 14}};
128  BOOST_TEST(people == ref, boost::test_tools::per_element{});
129 }
130 
131 BOOST_AUTO_TEST_SUITE_END()
static QCString name
Definition: declinfo.cpp:673
ChannelGroupService::Name Name
::geo::Vector_t toVector(Vector const &v)
Convert the specified vector into a geo::Vector_t.
STL namespace.
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
BOOST_AUTO_TEST_CASE(tupleAs_simple)
Definition: tupleAs_t.cc:90
static Config * config
Definition: config.cpp:1054
p
Definition: test.py:223
#define Comment
std::ostream & operator<<(std::ostream &, ParameterSetID const &)
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept