keymap_table_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test types keymap for tables:
4 //
5 // The purpose of this test is to verify that types 14-21 below create
6 // the correct key maps for ParameterSet validation.
7 //
8 // ======================================================================
9 
10 #define BOOST_TEST_MODULE (keymap test with tables)
11 
12 #include "boost/test/unit_test.hpp"
13 
14 #include "KeyMap.h"
15 #include "fhiclcpp/types/Atom.h"
17 #include "fhiclcpp/types/Table.h"
19 #include "fhiclcpp/types/Tuple.h"
20 
21 #include <string>
22 
23 using namespace fhicl;
24 using namespace fhicl::detail;
25 using namespace std;
26 
27 namespace {
28  struct S {
29  Atom<int> test{Name("atom")};
30  Sequence<int, 2> seq{Name("sequence")};
31  Tuple<int, double, bool> tuple{Name("tuple")};
32  };
33 }
34 
35 BOOST_AUTO_TEST_SUITE(types_keymap_test)
36 
37 // [14] Table<S>
39 {
40  auto map = KeyMap::get<Table<S>>("table");
41  auto ref = {"table",
42  "table.atom",
43  "table.sequence",
44  "table.sequence[0]",
45  "table.sequence[1]",
46  "table.tuple",
47  "table.tuple[0]",
48  "table.tuple[1]",
49  "table.tuple[2]"};
50  BOOST_TEST(map == ref, boost::test_tools::per_element{});
51 }
52 
53 // [15] Sequence< Table<S> >
54 BOOST_AUTO_TEST_CASE(table_in_seq_t)
55 {
56  auto map = KeyMap::get<Sequence<Table<S>>>("seqtable");
57 
58  auto ref = {"seqtable",
59  "seqtable[0]",
60  "seqtable[0].atom",
61  "seqtable[0].sequence",
62  "seqtable[0].sequence[0]",
63  "seqtable[0].sequence[1]",
64  "seqtable[0].tuple",
65  "seqtable[0].tuple[0]",
66  "seqtable[0].tuple[1]",
67  "seqtable[0].tuple[2]"};
68  BOOST_TEST(map == ref, boost::test_tools::per_element{});
69 }
70 
71 // [16] Sequence< Table<S>,2 >
72 BOOST_AUTO_TEST_CASE(table_in_seq_2_t)
73 {
74  auto map = KeyMap::get<Sequence<Table<S>, 2>>("seqtable");
75  auto ref = {"seqtable",
76  "seqtable[0]",
77  "seqtable[0].atom",
78  "seqtable[0].sequence",
79  "seqtable[0].sequence[0]",
80  "seqtable[0].sequence[1]",
81  "seqtable[0].tuple",
82  "seqtable[0].tuple[0]",
83  "seqtable[0].tuple[1]",
84  "seqtable[0].tuple[2]",
85  "seqtable[1]",
86  "seqtable[1].atom",
87  "seqtable[1].sequence",
88  "seqtable[1].sequence[0]",
89  "seqtable[1].sequence[1]",
90  "seqtable[1].tuple",
91  "seqtable[1].tuple[0]",
92  "seqtable[1].tuple[1]",
93  "seqtable[1].tuple[2]"};
94  BOOST_TEST(map == ref, boost::test_tools::per_element{});
95 }
96 
97 // [17] Tuple< Table<S>, U... >
98 BOOST_AUTO_TEST_CASE(table_in_tuple_t)
99 {
100  auto map = KeyMap::get<Tuple<Table<S>, int, double>>("tuptable");
101  auto ref = {"tuptable",
102  "tuptable[0]",
103  "tuptable[0].atom",
104  "tuptable[0].sequence",
105  "tuptable[0].sequence[0]",
106  "tuptable[0].sequence[1]",
107  "tuptable[0].tuple",
108  "tuptable[0].tuple[0]",
109  "tuptable[0].tuple[1]",
110  "tuptable[0].tuple[2]",
111  "tuptable[1]",
112  "tuptable[2]"};
113  BOOST_TEST(map == ref, boost::test_tools::per_element{});
114 }
115 
116 // [18] Tuple< Sequence< Table<S> >, U... >
117 BOOST_AUTO_TEST_CASE(seqtable_in_tuple_t)
118 {
119  auto map = KeyMap::get<Tuple<Sequence<Table<S>>, int, double>>("seqtuptable");
120  auto ref = {"seqtuptable",
121  "seqtuptable[0]",
122  "seqtuptable[0][0]",
123  "seqtuptable[0][0].atom",
124  "seqtuptable[0][0].sequence",
125  "seqtuptable[0][0].sequence[0]",
126  "seqtuptable[0][0].sequence[1]",
127  "seqtuptable[0][0].tuple",
128  "seqtuptable[0][0].tuple[0]",
129  "seqtuptable[0][0].tuple[1]",
130  "seqtuptable[0][0].tuple[2]",
131  "seqtuptable[1]",
132  "seqtuptable[2]"};
133  BOOST_TEST(map == ref, boost::test_tools::per_element{});
134 }
135 
136 // [19] Tuple< Sequence< Table<S>, SZ >, U... >
137 BOOST_AUTO_TEST_CASE(seqtable_2_in_tuple_t)
138 {
139  auto map =
140  KeyMap::get<Tuple<Sequence<Table<S>, 2>, int, double>>("seqtuptable");
141  auto ref = {"seqtuptable",
142  "seqtuptable[0]",
143  "seqtuptable[0][0]",
144  "seqtuptable[0][0].atom",
145  "seqtuptable[0][0].sequence",
146  "seqtuptable[0][0].sequence[0]",
147  "seqtuptable[0][0].sequence[1]",
148  "seqtuptable[0][0].tuple",
149  "seqtuptable[0][0].tuple[0]",
150  "seqtuptable[0][0].tuple[1]",
151  "seqtuptable[0][0].tuple[2]",
152  "seqtuptable[0][1]",
153  "seqtuptable[0][1].atom",
154  "seqtuptable[0][1].sequence",
155  "seqtuptable[0][1].sequence[0]",
156  "seqtuptable[0][1].sequence[1]",
157  "seqtuptable[0][1].tuple",
158  "seqtuptable[0][1].tuple[0]",
159  "seqtuptable[0][1].tuple[1]",
160  "seqtuptable[0][1].tuple[2]",
161  "seqtuptable[1]",
162  "seqtuptable[2]"};
163  BOOST_TEST(map == ref, boost::test_tools::per_element{});
164 }
165 
166 // [20] Sequence< Tuple< Table<S>, U... > >
167 BOOST_AUTO_TEST_CASE(tuptable_in_seq_t)
168 {
169  auto map = KeyMap::get<Sequence<Tuple<Table<S>, int, double>>>("tupseqtable");
170  auto ref = {"tupseqtable",
171  "tupseqtable[0]",
172  "tupseqtable[0][0]",
173  "tupseqtable[0][0].atom",
174  "tupseqtable[0][0].sequence",
175  "tupseqtable[0][0].sequence[0]",
176  "tupseqtable[0][0].sequence[1]",
177  "tupseqtable[0][0].tuple",
178  "tupseqtable[0][0].tuple[0]",
179  "tupseqtable[0][0].tuple[1]",
180  "tupseqtable[0][0].tuple[2]",
181  "tupseqtable[0][1]",
182  "tupseqtable[0][2]"};
183  BOOST_TEST(map == ref, boost::test_tools::per_element{});
184 }
185 
186 // [21] Sequence< Tuple< Table<S>, U... >, SZ >
187 BOOST_AUTO_TEST_CASE(tuptable_in_seq_2_t)
188 {
189  auto map =
190  KeyMap::get<Sequence<Tuple<Table<S>, int, double>, 2>>("tupseqtable");
191  auto ref = {"tupseqtable",
192  "tupseqtable[0]",
193  "tupseqtable[0][0]",
194  "tupseqtable[0][0].atom",
195  "tupseqtable[0][0].sequence",
196  "tupseqtable[0][0].sequence[0]",
197  "tupseqtable[0][0].sequence[1]",
198  "tupseqtable[0][0].tuple",
199  "tupseqtable[0][0].tuple[0]",
200  "tupseqtable[0][0].tuple[1]",
201  "tupseqtable[0][0].tuple[2]",
202  "tupseqtable[0][1]",
203  "tupseqtable[0][2]",
204  "tupseqtable[1]",
205  "tupseqtable[1][0]",
206  "tupseqtable[1][0].atom",
207  "tupseqtable[1][0].sequence",
208  "tupseqtable[1][0].sequence[0]",
209  "tupseqtable[1][0].sequence[1]",
210  "tupseqtable[1][0].tuple",
211  "tupseqtable[1][0].tuple[0]",
212  "tupseqtable[1][0].tuple[1]",
213  "tupseqtable[1][0].tuple[2]",
214  "tupseqtable[1][1]",
215  "tupseqtable[1][2]"};
216  BOOST_TEST(map == ref, boost::test_tools::per_element{});
217 }
218 
219 // [21] Sequence< Tuple< Table<S>, U... >, SZ >
220 BOOST_AUTO_TEST_CASE(tablefragment_t)
221 {
223  BOOST_TEST(tf().test.key() == "atom");
224 
225  {
226  KeyMap km;
227  km.walk_over(tf().seq);
228  auto mapseq = km.result();
229  auto refseq = {"sequence", "sequence[0]", "sequence[1]"};
230  BOOST_TEST(mapseq == refseq, boost::test_tools::per_element{});
231  }
232 
233  {
234  KeyMap km;
235  km.walk_over(tf().tuple);
236  auto maptup = km.result();
237  auto reftup = {"tuple", "tuple[0]", "tuple[1]", "tuple[2]"};
238  BOOST_TEST(maptup == reftup, boost::test_tools::per_element{});
239  }
240 }
241 
242 BOOST_AUTO_TEST_SUITE_END()
ChannelGroupService::Name Name
STL namespace.
static constexpr double km
Definition: Units.h:64
void walk_over(tt::maybe_const_t< ParameterBase, C > &)
auto const & result() const
Definition: KeyMap.h:16
BOOST_AUTO_TEST_CASE(table_t)