return_value_defaults_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test types return values with defaults:
4 //
5 // verify that types 1-13 below return the correct values
6 //
7 // ======================================================================
8 
9 #define BOOST_TEST_MODULE (return value defaults)
10 
11 #include "boost/test/unit_test.hpp"
12 
13 #include "fhiclcpp/types/Atom.h"
15 #include "fhiclcpp/types/Tuple.h"
16 
17 #include <string>
18 #include <vector>
19 
20 using namespace fhicl;
21 using namespace fhicl::detail;
22 using namespace std;
23 
24 BOOST_AUTO_TEST_SUITE(types_return_value_defaults_test)
25 
26 // [1] Atom<T>
28 {
29  Atom<int> test{Name("atom"), 4};
30  BOOST_TEST(test() == 4);
31 }
32 
33 // [2] Sequence<T>
34 BOOST_AUTO_TEST_CASE(one_sequence_t)
35 {
36  auto ref = {1, 2, 4};
37  Sequence<int> test{Name("sequence"), ref};
38  BOOST_TEST(test() == ref, boost::test_tools::per_element{});
39  std::size_t i{};
40  for (auto const& elem : ref)
41  BOOST_TEST(elem == test(i++));
42 }
43 
44 // [3] Sequence<T,SZ>
45 BOOST_AUTO_TEST_CASE(one_sequence_2_t)
46 {
47  auto ref = {5, 7};
48  Sequence<int, 2> test{Name("sequence"), ref};
49  BOOST_TEST(test() == ref, boost::test_tools::per_element{});
50 
51  std::size_t i{};
52  for (auto const& elem : ref)
53  BOOST_TEST(elem == test(i++));
54 }
55 
56 // [4] Tuple<T...>
58 {
59  Tuple<int, double, bool> test{Name("tuple"), {4, 1.5, false}};
60  BOOST_TEST(test.get<0>() == 4);
61  BOOST_TEST(test.get<1>() == 1.5);
62  BOOST_TEST(test.get<2>() == false);
63 }
64 
65 // [5] Tuple< Sequence<T>, U...>
66 BOOST_AUTO_TEST_CASE(seq_in_tuple_t)
67 {
68  auto ref = {1, 3, 5};
69  Tuple<Sequence<int>, double, bool> test{Name("tuple"), {ref, 4.6, true}};
70  BOOST_TEST(test.get<0>() == ref, boost::test_tools::per_element{});
71  BOOST_TEST(test.get<1>() == 4.6);
72  BOOST_TEST(test.get<2>() == true);
73 }
74 
75 // [6] Tuple< Sequence<T,SZ>, U...>
76 BOOST_AUTO_TEST_CASE(bounded_seq_in_tuple_t)
77 {
78  auto ref = {9, 15};
79  Tuple<Sequence<int, 2>, double, bool> test{Name("tuple"), {ref, 0.2, false}};
80  BOOST_TEST(test.get<0>() == ref, boost::test_tools::per_element{});
81  BOOST_TEST(test.get<1>() == 0.2);
82  BOOST_TEST(test.get<2>() == false);
83 }
84 
85 // [7] Tuple< Tuple<T...>, U...>
86 BOOST_AUTO_TEST_CASE(tuple_in_tuple_t)
87 {
88  Tuple<Tuple<int, float>, double, bool> test{Name("tuple"),
89  {{4, 3.7f}, 8.1, true}};
90  auto const tuple0 = test.get<0>();
91  BOOST_TEST(std::get<0>(tuple0) == 4);
92  BOOST_TEST(std::get<1>(tuple0) == 3.7f);
93  BOOST_TEST(test.get<1>() == 8.1);
94  BOOST_TEST(test.get<2>() == true);
95 }
96 
97 // [8] Sequence< Tuple<T...> >
98 BOOST_AUTO_TEST_CASE(tuple_in_seq_t)
99 {
100  std::vector<std::tuple<int, float>> ref_vec{std::make_tuple(2, 5.4f),
101  std::make_tuple(4, 104.5f),
102  std::make_tuple(8, 15.3f)};
103  Sequence<Tuple<int, float>> test{Name("seqtuple"),
104  {{2, 5.4f}, {4, 104.5f}, {8, 15.3f}}};
105  std::size_t i{};
106  for (auto const& elem : test()) {
107  BOOST_TEST(std::get<0>(elem) == std::get<0>(ref_vec.at(i)));
108  BOOST_TEST(std::get<1>(elem) == std::get<1>(ref_vec.at(i++)));
109  }
110 }
111 
112 // [9] Sequence< Tuple<T...>, SZ >
113 BOOST_AUTO_TEST_CASE(tuple_in_seq_2_t)
114 {
115  std::array<std::tuple<int, float>, 2> ref_vec{
116  {std::make_tuple(1, 2.3f), std::make_tuple(9, 3.2f)}};
117 
118  Sequence<Tuple<int, float>, 2> test{Name("seqtuple"), {{1, 2.3f}, {9, 3.2f}}};
119  std::size_t i{};
120  for (auto const& elem : test()) {
121  BOOST_TEST(std::get<0>(elem) == std::get<0>(ref_vec.at(i)));
122  BOOST_TEST(std::get<1>(elem) == std::get<1>(ref_vec.at(i++)));
123  }
124 }
125 
126 // [10] Sequence< Sequence<T> >
127 BOOST_AUTO_TEST_CASE(seq_in_seq_t)
128 {
129  auto ref_vec = std::vector<std::vector<int>>{{1, 5, 7}, {2}};
130  Sequence<Sequence<int>> test{Name("seqseq"), {{1, 5, 7}, {2}}};
131  std::size_t i{};
132  for (auto const& val : test()) {
133  auto ref = ref_vec.at(i++);
134  BOOST_TEST(val == ref);
135  }
136 
137  i = 0ul;
138  for (auto const& ref : ref_vec) {
139  auto val = test(i++);
140  BOOST_TEST(val == ref);
141  }
142 }
143 
144 // [11] Sequence< Sequence<T,SZ> >
145 BOOST_AUTO_TEST_CASE(seq_2_in_seq_t)
146 {
147  auto ref_vec = std::vector<std::array<int, 2>>{{{1, 2}}};
148  Sequence<Sequence<int, 2>> test{Name("seqseq"), {{1, 2}}};
149  std::size_t i{};
150  for (auto const& val : test()) {
151  auto ref = ref_vec.at(i++);
152  BOOST_TEST(val == ref);
153  }
154 }
155 
156 // [12] Sequence< Sequence<T>,SZ >
157 BOOST_AUTO_TEST_CASE(seq_in_seq_2_t)
158 {
159  std::array<std::vector<int>, 2> ref_vec{
160  {std::vector<int>{4}, std::vector<int>{{1, 4, 9, 1}}}};
161 
162  Sequence<Sequence<int>, 2> test{Name("seqseq"), {{4}, {1, 4, 9, 1}}};
163  std::size_t i{};
164  for (auto const& val : test()) {
165  auto ref = ref_vec.at(i++);
166  BOOST_TEST(val == ref);
167  }
168 }
169 
170 // [13] Sequence< Sequence<T,SZ>, SZ >
171 BOOST_AUTO_TEST_CASE(seq_2_in_seq_2_t)
172 {
173  std::array<std::array<int, 2>, 2> ref_vec{
174  {std::array<int, 2>{{6, 7}}, std::array<int, 2>{{2, 1}}}};
175 
176  Sequence<Sequence<int, 2>, 2> test{Name("seqseq"), {{6, 7}, {2, 1}}};
177  std::size_t i{};
178  for (auto const& val : test()) {
179  auto ref = ref_vec.at(i++);
180  BOOST_TEST(val == ref);
181  }
182 }
183 BOOST_AUTO_TEST_SUITE_END()
ChannelGroupService::Name Name
STL namespace.
BOOST_AUTO_TEST_CASE(one_atom_t)