keymap_defaults_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test types keymap with defaults:
4 //
5 // The purpose of this test is to verify that types 1-13 create
6 // the correct key maps for ParameterSet validation whenever default
7 // arguments are included during construction.
8 //
9 // ======================================================================
10 
11 #define BOOST_TEST_MODULE (keymap test)
12 
13 #include "boost/test/unit_test.hpp"
14 
15 #include "KeyMap.h"
16 #include "fhiclcpp/types/Atom.h"
18 #include "fhiclcpp/types/Tuple.h"
19 
20 #include <string>
21 
22 using namespace fhicl;
23 using namespace fhicl::detail;
24 using namespace std;
25 
26 BOOST_AUTO_TEST_SUITE(types_keymap_defaults_test)
27 
28 // [1] Atom<T>
30 {
31  KeyMap km;
32  Atom<int> test{Name("atom"), 4};
33  km.walk_over(test);
34 
35  auto map = km.result();
36  auto ref = {"atom"};
37  BOOST_TEST(map == ref, boost::test_tools::per_element{});
38 }
39 
40 // [2] Sequence<T>
41 BOOST_AUTO_TEST_CASE(one_sequence_t)
42 {
43  KeyMap km;
44  Sequence<int> test{Name("sequence"), {1, 2, 4}};
45  km.walk_over(test);
46 
47  auto map = km.result();
48  auto ref = {"sequence", "sequence[0]", "sequence[1]", "sequence[2]"};
49  BOOST_TEST(map == ref, boost::test_tools::per_element{});
50 }
51 
52 // [3] Sequence<T,SZ>
53 BOOST_AUTO_TEST_CASE(one_sequence_2_t)
54 {
55  KeyMap km;
56  Sequence<int, 2> test{Name("sequence"), {5, 7}};
57  km.walk_over(test);
58 
59  auto map = km.result();
60  auto ref = {"sequence", "sequence[0]", "sequence[1]"};
61  BOOST_TEST(map == ref, boost::test_tools::per_element{});
62 }
63 
64 // [4] Tuple<T...>
66 {
67  KeyMap km;
68  Tuple<int, double, bool> test{Name("tuple"), {4, 1.5, false}};
69  km.walk_over(test);
70 
71  auto map = km.result();
72  auto ref = {"tuple", "tuple[0]", "tuple[1]", "tuple[2]"};
73  BOOST_TEST(map == ref, boost::test_tools::per_element{});
74 }
75 
76 // [5] Tuple< Sequence<T>, U...>
77 BOOST_AUTO_TEST_CASE(seq_in_tuple_t)
78 {
79  KeyMap km;
80  Tuple<Sequence<int>, double, bool> test{Name("tuple"),
81  {{1, 3, 5}, 4.6, true}};
82  km.walk_over(test);
83 
84  auto map = km.result(); // key_map(&test);
85  auto ref = {"tuple",
86  "tuple[0]",
87  "tuple[0][0]",
88  "tuple[0][1]",
89  "tuple[0][2]",
90  "tuple[1]",
91  "tuple[2]"};
92  BOOST_TEST(map == ref, boost::test_tools::per_element{});
93 }
94 
95 // [6] Tuple< Sequence<T,SZ>, U...>
96 BOOST_AUTO_TEST_CASE(bounded_seq_in_tuple_t)
97 {
98  KeyMap km;
99  Tuple<Sequence<int, 2>, double, bool> test{Name("tuple"),
100  {{9, 15}, 0.2, false}};
101  km.walk_over(test);
102 
103  auto map = km.result();
104  auto ref = {
105  "tuple", "tuple[0]", "tuple[0][0]", "tuple[0][1]", "tuple[1]", "tuple[2]"};
106  BOOST_TEST(map == ref, boost::test_tools::per_element{});
107 }
108 
109 // [7] Tuple< Tuple<T...>, U...>
110 BOOST_AUTO_TEST_CASE(tuple_in_tuple_t)
111 {
112  KeyMap km;
113  Tuple<Tuple<int, float>, double, bool> test{Name("tuple"),
114  {{4, 3.7f}, 8.1, true}};
115  km.walk_over(test);
116 
117  auto map = km.result();
118  auto ref = {
119  "tuple", "tuple[0]", "tuple[0][0]", "tuple[0][1]", "tuple[1]", "tuple[2]"};
120  BOOST_TEST(map == ref, boost::test_tools::per_element{});
121 }
122 
123 // [8] Sequence< Tuple<T...> >
124 BOOST_AUTO_TEST_CASE(tuple_in_seq_t)
125 {
126  KeyMap km;
127  Sequence<Tuple<int, float>> test{Name("seqtuple"),
128  {{2, 5.4f}, {4, 104.5f}, {8, 15.3f}}};
129  km.walk_over(test);
130 
131  auto map = km.result();
132  auto ref = {"seqtuple",
133  "seqtuple[0]",
134  "seqtuple[0][0]",
135  "seqtuple[0][1]",
136  "seqtuple[1]",
137  "seqtuple[1][0]",
138  "seqtuple[1][1]",
139  "seqtuple[2]",
140  "seqtuple[2][0]",
141  "seqtuple[2][1]"};
142  BOOST_TEST(map == ref, boost::test_tools::per_element{});
143 }
144 
145 // [9] Sequence< Tuple<T...>, SZ >
146 BOOST_AUTO_TEST_CASE(tuple_in_seq_2_t)
147 {
148  KeyMap km;
149  Sequence<Tuple<int, float>, 2> test{Name("seqtuple"), {{1, 2.3f}, {9, 3.2f}}};
150  km.walk_over(test);
151 
152  auto map = km.result();
153  auto ref = {"seqtuple",
154  "seqtuple[0]",
155  "seqtuple[0][0]",
156  "seqtuple[0][1]",
157  "seqtuple[1]",
158  "seqtuple[1][0]",
159  "seqtuple[1][1]"};
160  BOOST_TEST(map == ref, boost::test_tools::per_element{});
161 }
162 
163 // [10] Sequence< Sequence<T> >
164 BOOST_AUTO_TEST_CASE(seq_in_seq_t)
165 {
166  KeyMap km;
167  Sequence<Sequence<int>> test{Name("seqseq"), {{1, 5, 7}, {2}}};
168  km.walk_over(test);
169 
170  auto map = km.result();
171  auto ref = {"seqseq",
172  "seqseq[0]",
173  "seqseq[0][0]",
174  "seqseq[0][1]",
175  "seqseq[0][2]",
176  "seqseq[1]",
177  "seqseq[1][0]"};
178  BOOST_TEST(map == ref, boost::test_tools::per_element{});
179 }
180 
181 // [11] Sequence< Sequence<T,SZ> >
182 BOOST_AUTO_TEST_CASE(seq_2_in_seq_t)
183 {
184  KeyMap km;
185  Sequence<Sequence<int, 2>> test{Name("seqseq"), {{1, 2}}};
186  km.walk_over(test);
187 
188  auto map = km.result();
189  auto ref = {"seqseq", "seqseq[0]", "seqseq[0][0]", "seqseq[0][1]"};
190  BOOST_TEST(map == ref, boost::test_tools::per_element{});
191 }
192 
193 // [12] Sequence< Sequence<T>, SZ >
194 BOOST_AUTO_TEST_CASE(seq_in_seq_2_t)
195 {
196  KeyMap km;
197  Sequence<Sequence<int>, 2> test{Name("seqseq"), {{4}, {1, 4, 9, 1}}};
198  km.walk_over(test);
199 
200  auto map = km.result();
201  auto ref = {"seqseq",
202  "seqseq[0]",
203  "seqseq[0][0]",
204  "seqseq[1]",
205  "seqseq[1][0]",
206  "seqseq[1][1]",
207  "seqseq[1][2]",
208  "seqseq[1][3]"};
209  BOOST_TEST(map == ref, boost::test_tools::per_element{});
210 }
211 
212 // [13] Sequence< Sequence<T,SZ>, SZ >
213 BOOST_AUTO_TEST_CASE(seq_2_in_seq_2_t)
214 {
215  KeyMap km;
216  Sequence<Sequence<int, 2>, 2> test{Name("seqseq"), {{6, 7}, {2, 1}}};
217  km.walk_over(test);
218 
219  auto map = km.result();
220  auto ref = {"seqseq",
221  "seqseq[0]",
222  "seqseq[0][0]",
223  "seqseq[0][1]",
224  "seqseq[1]",
225  "seqseq[1][0]",
226  "seqseq[1][1]"};
227  BOOST_TEST(map == ref, boost::test_tools::per_element{});
228 }
229 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(one_atom_t)
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