return_table_values_from_fcl_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test table return values from FHiCL files
4 //
5 // The purpose of this test is to verify that all table values
6 // are accurately retrieved after being validated.
7 //
8 // ======================================================================
9 
10 #define BOOST_TEST_MODULE (return table values from fcl)
11 
12 #include "boost/test/unit_test.hpp"
13 
14 #include "fhiclcpp/types/Atom.h"
16 #include "fhiclcpp/types/Table.h"
18 #include "fhiclcpp/types/Tuple.h"
19 
20 #include "FixtureBase.h"
21 
22 #include <iostream>
23 #include <limits>
24 #include <string>
25 #include <vector>
26 
27 using namespace fhicl;
28 using namespace fhicl::detail;
29 using namespace std;
30 
31 namespace {
32 
33  constexpr auto tolerance = std::numeric_limits<double>::epsilon();
34 
35  struct RefS {
36 
37  RefS(int const i,
38  int const sj,
39  int const sk,
40  int const tl,
41  string const str,
42  bool const flag)
43  : i_(i), sj_(sj), sk_(sk), tl_(tl), str_(str), flag_(flag)
44  {}
45 
46  int i_;
47  int sj_;
48  int sk_;
49  int tl_;
50  string str_;
51  bool flag_;
52  };
53 
54  std::ostream& operator<< [[maybe_unused]](std::ostream& os, RefS const& refs)
55  {
56  os << " Atom: " << refs.i_ << " Sequence: [ " << refs.sj_ << ", "
57  << refs.sk_ << " ]"
58  << " Tuple: [ " << refs.tl_ << ", " << refs.str_ << ", "
59  << std::boolalpha << refs.flag_ << " ]";
60  return os;
61  }
62 
63  struct S {
64  Atom<int> atom{Name("atom")};
65  Sequence<int, 2> sequence{Name("sequence")};
66  Tuple<int, string, bool> tuple{Name("tuple")};
67 
68  bool
69  operator==(const RefS& refs) const
70  {
71  return this->atom() == refs.i_ && this->sequence(0) == refs.sj_ &&
72  this->sequence(1) == refs.sk_ &&
73  this->tuple.get<0>() == refs.tl_ &&
74  this->tuple.get<1>() == refs.str_ &&
75  this->tuple.get<2>() == refs.flag_;
76  }
77  };
78 
79  std::ostream& operator<< [[maybe_unused]](std::ostream& os, S const& s)
80  {
81  os << " Atom: " << s.atom() << " Sequence: [ " << s.sequence(0) << ", "
82  << s.sequence(1) << " ]"
83  << " Tuple: [ " << s.tuple.get<0>() << ", " << s.tuple.get<1>() << ", "
84  << std::boolalpha << s.tuple.get<2>() << " ]";
85  return os;
86  }
87 
88  struct Configuration {
89  Table<S> table{Name("table")};
90  Sequence<Table<S>> vecOfTable{Name("vecOfTable")};
91  Sequence<Table<S>, 2> arrOfTable{Name("arrOfTable")};
92  Tuple<Table<S>, int, double> tupWithTable{Name("tupWithTable")};
93  Tuple<Sequence<Table<S>>, int, double> tupWithVecTable{
94  Name("tupWithVecTable")};
95  Tuple<Sequence<Table<S>, 2>, int, double> tupWithArrTable{
96  Name("tupWithArrTable")};
97  Sequence<Tuple<Table<S>, int, double>> vecWithTupTable{
98  Name("vecWithTupTable")};
99  Sequence<Tuple<Table<S>, int, double>, 2> arrWithTupTable{
100  Name("arrWithTupTable")};
101  TableFragment<S> tFragment;
102  };
103 
104  struct Fixture : fhiclcpp_types::FixtureBase<Configuration> {
105  Fixture() : FixtureBase("return_table_values_from_fcl_t.fcl") {}
106  };
107 }
108 
109 // provide use of 'Table<Configuration> config'
110 BOOST_FIXTURE_TEST_SUITE(values_from_fcl, Fixture)
111 
112 // [14] Table<S>
114 {
115  RefS ref(4, 3, 6, 8, "something", false);
116  BOOST_TEST(config().table() == ref);
117 }
118 
119 // [15] Sequence< Table<S> >
120 BOOST_AUTO_TEST_CASE(table_in_seq_t)
121 {
122  auto ref = {RefS{0, 10, 100, 0, "something0", true}};
123  auto it = ref.begin();
124 
125  for (auto const& table : config().vecOfTable())
126  BOOST_TEST(table == *it++);
127 }
128 
129 // [16] Sequence< Table<S>,2 >
130 BOOST_AUTO_TEST_CASE(table_in_seq_2_t)
131 {
132  auto ref = {RefS{0, 10, 100, 0, "array0", true},
133  RefS{1, 11, 101, 1, "array1", true}};
134 
135  auto it = ref.begin();
136 
137  for (auto const& table : config().arrOfTable())
138  BOOST_TEST(table == *it++);
139 }
140 
141 // [17] Tuple< Table<S>, U... >
142 BOOST_AUTO_TEST_CASE(table_in_tuple_t)
143 {
144  RefS ref{3, 13, 103, 3, "tup0", true};
145  BOOST_TEST(config().tupWithTable.get<0>() == ref);
146  BOOST_TEST(config().tupWithTable.get<1>() == 981);
147  BOOST_TEST(config().tupWithTable.get<2>() == 581.1, tolerance);
148 }
149 
150 // [18] Tuple< Sequence< Table<S> >, U... >
151 BOOST_AUTO_TEST_CASE(vec_table_in_tuple_t)
152 {
153  auto ref = {RefS{4, 14, 104, 4, "tup0", true}};
154  auto it = ref.begin();
155  for (auto const& table : config().tupWithVecTable.get<0>())
156  BOOST_TEST(table == *it++);
157  BOOST_TEST(config().tupWithVecTable.get<1>() == 345);
158  BOOST_TEST(config().tupWithVecTable.get<2>() == 234.14, tolerance);
159 }
160 
161 // [19] Tuple< Sequence< Table<S>, SZ >, U... >
162 BOOST_AUTO_TEST_CASE(arr_table_in_tuple_t)
163 {
164  auto ref = {RefS{5, 15, 105, 5, "tup0", true},
165  RefS{6, 16, 106, 6, "tup1", true}};
166  auto it = ref.begin();
167 
168  for (auto const& table : config().tupWithArrTable.get<0>())
169  BOOST_TEST(table == *it++);
170  BOOST_TEST(config().tupWithArrTable.get<1>() == 789);
171  BOOST_TEST(config().tupWithArrTable.get<2>() == 17.06, tolerance);
172 }
173 
174 // [20] Sequence< Tuple< Table<S>, U... > >
175 BOOST_AUTO_TEST_CASE(tup_table_in_vec_t)
176 {
177  auto ref = RefS{7, 17, 107, 7, "tup0", true};
178 
179  for (auto const& tup : config().vecWithTupTable()) {
180  BOOST_TEST(std::get<0>(tup) == ref);
181  BOOST_TEST(std::get<1>(tup) == 4);
182  BOOST_TEST(std::get<2>(tup) == 1.0004, tolerance);
183  }
184 }
185 
186 // [21] Sequence< Tuple< Table<S>, U... >, SZ >
187 BOOST_AUTO_TEST_CASE(tup_table_in_arr_t)
188 {
189  auto ref_ts = {RefS{8, 18, 108, 8, "tup0", true},
190  RefS{9, 19, 109, 9, "tup1", true}};
191  auto ref_is = {4, 40};
192  auto ref_ds = {0.89881, 1.47412};
193 
194  auto it_ts = ref_ts.begin();
195  auto it_is = ref_is.begin();
196  auto it_ds = ref_ds.begin();
197 
198  for (auto const& tup : config().arrWithTupTable()) {
199  BOOST_TEST(std::get<0>(tup) == *it_ts++);
200  BOOST_TEST(std::get<1>(tup) == *it_is++);
201  BOOST_TEST(std::get<2>(tup) == *it_ds++, tolerance);
202  }
203 }
204 
205 // [22] TableFragment<S>
206 BOOST_AUTO_TEST_CASE(tableFragment_t)
207 {
208  auto ref = RefS{10, 20, 200, 10, "tup", false};
209  BOOST_TEST(config().tFragment() == ref);
210 }
211 
212 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(table_t)
auto const tolerance
ChannelGroupService::Name Name
STL namespace.
static Config * config
Definition: config.cpp:1054
static QCString * s
Definition: config.cpp:1042
static QCString str
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept