#include "boost/test/unit_test.hpp"
#include "fhiclcpp/ParameterSet.h"
#include <complex>
#include <limits>
#include <string>
#include <vector>
Go to the source code of this file.
using uint = unsigned int |
BOOST_AUTO_TEST_CASE |
( |
bool_values |
| ) |
|
Definition at line 31 of file values_test.cc.
35 pset.
put<
string>(
"b11",
"true");
39 BOOST_TEST(pset.
to_string() ==
"b11:\"true\"");
40 BOOST_TEST(pset.
get<
bool>(
"b11"));
41 pset.
put<
string>(
"b13",
"\"false\"");
42 BOOST_TEST(pset.
to_string() ==
"b11:\"true\" b13:\"false\"");
43 BOOST_TEST(!pset.
get<
bool>(
"b13"));
48 pset.
put<
bool>(
"b21",
true);
49 BOOST_TEST(pset.
get<
string>(
"b21") ==
"true");
50 BOOST_TEST(pset.
to_string() ==
"b21:true");
51 BOOST_TEST(pset.
get<
bool>(
"b21"));
52 pset.
put<
bool>(
"b24",
false);
53 BOOST_TEST(pset.
get<
string>(
"b24") ==
"false");
54 BOOST_TEST(pset.
to_string() ==
"b21:true b24:false");
55 BOOST_TEST(!pset.
get<
bool>(
"b24"));
60 pset.
put<
string>(
"b31",
"tru");
61 BOOST_TEST(pset.
to_string() ==
"b31:\"tru\"");
bool is_key_to_sequence(std::string const &key) const
bool is_key_to_table(std::string const &key) const
T get(std::string const &key) const
bool is_key_to_atom(std::string const &key) const
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
nil_value |
| ) |
|
Definition at line 66 of file values_test.cc.
68 using nil_t = std::nullptr_t;
74 pset.
put(
"n11", nil_t{});
75 BOOST_TEST(pset.
get<nil_t>(
"n11") == nil_t{});
76 BOOST_TEST(pset.
to_string() ==
"n11:@nil");
85 pset.
put<
string>(
"n21",
"nil");
87 BOOST_TEST(pset.
to_string() ==
"n11:@nil n21:\"nil\"");
89 pset.
put<
string>(
"n31",
"NIL");
90 BOOST_TEST(pset.
to_string() ==
"n11:@nil n21:\"nil\" n31:\"NIL\"");
94 BOOST_TEST(pset.
to_string() == pset2.to_string());
97 BOOST_TEST(pset3.to_string() ==
"n11:@nil n21:\"nil\" n31:\"@nil\"");
99 BOOST_TEST(pset3.get<
string>(
"n21") ==
"nil");
100 BOOST_TEST(pset3.get<
string>(
"n31") ==
"@nil");
T get(std::string const &key) const
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
string_values |
| ) |
|
Definition at line 103 of file values_test.cc.
108 pset.
put<
string>(
"n11",
"");
109 BOOST_TEST(pset.
get<
string>(
"n11") ==
"");
110 BOOST_TEST(pset.
to_string() ==
"n11:\"\"");
111 pset.
put<
string>(
"n13",
"a");
112 BOOST_TEST(pset.
get<
string>(
"n13") ==
"a");
113 BOOST_TEST(pset.
to_string() ==
"n11:\"\" n13:\"a\"");
114 pset.
put<
string>(
"n15",
"\"a\"");
115 BOOST_TEST(pset.
get<
string>(
"n15") ==
"a");
116 BOOST_TEST(pset.
to_string() ==
"n11:\"\" n13:\"a\" n15:\"a\"");
117 pset.
put<
string>(
"n17",
"'a b'");
118 BOOST_TEST(pset.
get<
string>(
"n17") ==
"a b");
119 BOOST_TEST(pset.
to_string() ==
"n11:\"\" n13:\"a\" n15:\"a\" n17:\"a b\"");
T get(std::string const &key) const
void put(std::string const &key)
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
unsigned_values |
| ) |
|
Definition at line 122 of file values_test.cc.
127 BOOST_TEST(pset.
get<
string>(
"u11") ==
"0");
129 BOOST_TEST(pset.
get<
uint>(
"u11") == 0u);
134 pset.
put<
string>(
"u21",
"000");
135 BOOST_TEST(pset.
to_string() ==
"u21:\"000\"");
137 BOOST_TEST(u21 == 0u);
139 BOOST_TEST(pset.
get<
string>(
"u23") ==
"0");
140 BOOST_TEST(pset.
to_string() ==
"u21:\"000\" u23:0");
145 pset.
put<
string>(
"u31",
"1.2e+1");
146 BOOST_TEST(pset.
to_string() ==
"u31:\"1.2e+1\"");
147 BOOST_TEST(pset.
get<
uint>(
"u31") == 12u);
152 pset.
put<
unsigned long>(
"u41", 123456ul);
153 BOOST_TEST(pset.
get<
string>(
"u41") ==
"123456");
154 BOOST_TEST(pset.
to_string() ==
"u41:123456");
155 BOOST_TEST(pset.
get<
unsigned long>(
"u41") == 123456ul);
156 pset.
put<
unsigned long>(
"u44", 1234567ul);
157 BOOST_TEST(pset.
get<
string>(
"u44") ==
"1.234567e+6");
158 BOOST_TEST(pset.
to_string() ==
"u41:123456 u44:1.234567e+6");
159 BOOST_TEST(pset.
get<
unsigned long>(
"u44") == 1234567ul);
T get(std::string const &key) const
void put(std::string const &key)
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
int_values |
| ) |
|
Definition at line 163 of file values_test.cc.
167 pset.
put<
int>(
"i1", 0);
168 BOOST_TEST(pset.
get<
string>(
"i1") ==
"0");
170 BOOST_TEST(pset.
get<
int>(
"i1") == 0);
175 pset.
put<
string>(
"i21",
"000");
176 BOOST_TEST(pset.
to_string() ==
"i21:\"000\"");
177 int i21 = pset.
get<
int>(
"i21");
178 BOOST_TEST(i21 == 0);
179 pset.
put<
int>(
"i23", i21);
180 BOOST_TEST(pset.
get<
string>(
"i23") ==
"0");
181 BOOST_TEST(pset.
to_string() ==
"i21:\"000\" i23:0");
186 pset.
put<
string>(
"i31",
"-1.2e+1");
187 BOOST_TEST(pset.
to_string() ==
"i31:\"-1.2e+1\"");
188 BOOST_TEST(pset.
get<
int>(
"i31") == -12);
193 pset.
put<
long>(
"i41", 123456);
194 BOOST_TEST(pset.
get<
string>(
"i41") ==
"123456");
195 BOOST_TEST(pset.
to_string() ==
"i41:123456");
196 BOOST_TEST(pset.
get<
long>(
"i41") == 123456);
197 pset.
put<
long>(
"i44", 1234567);
198 BOOST_TEST(pset.
get<
string>(
"i44") ==
"1.234567e+6");
199 BOOST_TEST(pset.
to_string() ==
"i41:123456 i44:1.234567e+6");
200 BOOST_TEST(pset.
get<
long>(
"i44") == 1234567);
205 pset.
put<
long>(
"i51", -123456);
206 BOOST_TEST(pset.
get<
string>(
"i51") ==
"-123456");
207 BOOST_TEST(pset.
to_string() ==
"i51:-123456");
208 BOOST_TEST(pset.
get<
long>(
"i51") == -123456);
209 pset.
put<
long>(
"i54", -1234567);
210 BOOST_TEST(pset.
get<
string>(
"i54") ==
"-1.234567e+6");
211 BOOST_TEST(pset.
to_string() ==
"i51:-123456 i54:-1.234567e+6");
212 BOOST_TEST(pset.
get<
long>(
"i54") == -1234567);
T get(std::string const &key) const
void put(std::string const &key)
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
float_values |
| ) |
|
Definition at line 216 of file values_test.cc.
220 pset.
put<
dbl>(
"f11", 0.0);
221 BOOST_TEST(pset.get<
string>(
"f11") ==
"0");
222 BOOST_TEST(pset.to_string() ==
"f11:0");
223 BOOST_TEST(pset.get<
dbl>(
"f11") == 0.0);
224 BOOST_TEST(pset.get<
int>(
"f11") == 0);
225 BOOST_TEST(pset.get<
uint>(
"f11") == 0u);
226 pset.put<
dbl>(
"f14", 12.0);
227 BOOST_TEST(pset.get<
string>(
"f14") ==
"12");
228 BOOST_TEST(pset.to_string() ==
"f11:0 f14:12");
229 BOOST_TEST(pset.get<
dbl>(
"f14") == 12.0);
230 BOOST_TEST(pset.get<
int>(
"f14") == 12);
231 BOOST_TEST(pset.get<
uint>(
"f14") == 12u);
232 pset.put<
dbl>(
"f17", 12.3e1);
233 BOOST_TEST(pset.get<
string>(
"f17") ==
"123");
234 BOOST_TEST(pset.to_string() ==
"f11:0 f14:12 f17:123");
235 BOOST_TEST(pset.get<
dbl>(
"f17") == 123.0);
236 BOOST_TEST(pset.get<
int>(
"f17") == 123);
237 BOOST_TEST(pset.get<
uint>(
"f17") == 123u);
242 pset.
put<
dbl>(
"f21", 12.3456e4);
243 BOOST_TEST(pset.
get<
string>(
"f21") ==
"123456");
244 BOOST_TEST(pset.
to_string() ==
"f21:123456");
245 BOOST_TEST(pset.
get<
dbl>(
"f21") == 123456.0);
246 BOOST_TEST(pset.
get<
int>(
"f21") == 123456);
247 BOOST_TEST(pset.
get<
uint>(
"f21") == 123456u);
248 pset.
put<
dbl>(
"f24", 12.34567e5);
249 BOOST_TEST(pset.
get<
string>(
"f24") ==
"1.234567e+6");
250 BOOST_TEST(pset.
to_string() ==
"f21:123456 f24:1.234567e+6");
251 BOOST_TEST(pset.
get<
dbl>(
"f24") == 1234567.0);
252 BOOST_TEST(pset.
get<
int>(
"f24") == 1234567L);
253 BOOST_TEST(pset.
get<
uint>(
"f24") == 1234567uL);
254 pset.
put<
dbl>(
"f27", 3.5);
255 BOOST_TEST(pset.
get<
string>(
"f27") ==
"3.5");
256 BOOST_TEST(pset.
to_string() ==
"f21:123456 f24:1.234567e+6 f27:3.5");
257 BOOST_TEST(pset.
get<
dbl>(
"f27") == 3.5);
264 pset.
put<
dbl>(
"f31", -12.3456e4);
265 BOOST_TEST(pset.
get<
string>(
"f31") ==
"-123456");
266 BOOST_TEST(pset.
to_string() ==
"f31:-123456");
267 BOOST_TEST(pset.
get<
dbl>(
"f31") == -123456.0);
268 pset.
put<
dbl>(
"f34", -12.34567e5);
269 BOOST_TEST(pset.
get<
string>(
"f34") ==
"-1.234567e+6");
270 BOOST_TEST(pset.
to_string() ==
"f31:-123456 f34:-1.234567e+6");
271 BOOST_TEST(pset.
get<
dbl>(
"f34") == -1234567.0);
272 pset.
put<
dbl>(
"f37", -12.34567e-5);
277 pset.
put<
dbl>(
"f41", numeric_limits<dbl>::infinity());
278 BOOST_TEST(pset.
get<
string>(
"f41") ==
"+infinity");
279 BOOST_TEST(pset.
to_string() ==
"f41:+infinity");
280 BOOST_TEST(pset.
get<
dbl>(
"f41") == numeric_limits<dbl>::infinity());
281 pset.
put<
dbl>(
"f44", -numeric_limits<dbl>::infinity());
282 BOOST_TEST(pset.
get<
string>(
"f44") ==
"-infinity");
283 BOOST_TEST(pset.
to_string() ==
"f41:+infinity f44:-infinity");
284 BOOST_TEST(pset.
get<
dbl>(
"f44") == -numeric_limits<dbl>::infinity());
T get(std::string const &key) const
std::numeric_limits< double > dbl
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
complex_values |
| ) |
|
Definition at line 288 of file values_test.cc.
293 BOOST_TEST(pset.
get<
string>(
"f11") ==
"(0,0)");
294 BOOST_TEST(pset.
to_string() ==
"f11:(0,0)");
297 BOOST_TEST(pset.
get<
string>(
"f14") ==
"(0,0)");
298 BOOST_TEST(pset.
to_string() ==
"f11:(0,0) f14:(0,0)");
299 BOOST_TEST(pset.
get<
cdbl>(
"f14") ==
cdbl(0.0, 0.0));
305 BOOST_TEST(pset.
to_string() ==
"f21:(1,2)");
307 BOOST_TEST(pset.
get<
cdbl>(
"f21") ==
cdbl(1.0, 2.0));
308 pset.
put<
string>(
"f24",
"(3.25 , 4.75 )");
310 BOOST_TEST(pset.
get<
cdbl>(
"f24") ==
cdbl(3.25, 4.75));
T get(std::string const &key) const
void put(std::string const &key)
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
sequence_values |
| ) |
|
Definition at line 314 of file values_test.cc.
319 pset.
put<
string>(
"f11",
"[]");
320 BOOST_TEST(pset.
get<
string>(
"f11") ==
"[]");
321 BOOST_TEST(pset.
to_string() ==
"f11:\"[]\"");
322 BOOST_TEST(pset.
get<
uvec>(
"f11").empty());
324 BOOST_TEST(pset.
get<
uvec>(
"f11") == uv);
327 BOOST_TEST(pset.
to_string() ==
"f11:\"[]\" f16:[]");
328 BOOST_TEST(pset.
get<
uvec>(
"f16") == uv);
331 pset.
put<
string>(
"f21",
"[1]");
332 BOOST_TEST(pset.
get<
string>(
"f21") ==
"[1]");
333 BOOST_TEST(pset.
to_string() ==
"f11:\"[]\" f16:[] f21:\"[1]\"");
334 BOOST_TEST(pset.
get<
uvec>(
"f21").size() == 1u);
335 BOOST_TEST(pset.
get<
uvec>(
"f21") == uv);
338 BOOST_TEST(pset.
to_string() ==
"f11:\"[]\" f16:[] f21:\"[1]\" f25:[1]");
339 BOOST_TEST(pset.
get<
uvec>(
"f25").size() == 1u);
340 BOOST_TEST(pset.
get<
uvec>(
"f25") == uv);
343 pset.
put<
string>(
"f31",
"[1,2]");
344 BOOST_TEST(pset.
get<
string>(
"f31") ==
"[1,2]");
345 BOOST_TEST(pset.
get<
uvec>(
"f31").size() == 2u);
346 BOOST_TEST(pset.
get<
uvec>(
"f31") == uv);
350 "f11:\"[]\" f16:[] f21:\"[1]\" f25:[1] f31:\"[1,2]\" f34:[1,2,3]");
352 BOOST_TEST(pset.
get<
uvec>(
"f34").size() == 3u);
353 BOOST_TEST(pset.
get<
uvec>(
"f34") == uv);
356 pset.
put<
string>(
"f41",
"[1,2,3,4]");
357 BOOST_TEST(pset.
get<
string>(
"f41") ==
"[1,2,3,4]");
358 BOOST_TEST(pset.
get<
uvec>(
"f41").size() == 4u);
359 BOOST_TEST(pset.
get<
uvec>(
"f41") == uv);
366 BOOST_TEST(pset.
get<
uvec>(
"f43").size() == 5u);
367 BOOST_TEST(pset.
get<
uvec>(
"f43") == uv);
bool is_key_to_sequence(std::string const &key) const
bool is_key_to_table(std::string const &key) const
T get(std::string const &key) const
bool is_key_to_atom(std::string const &key) const
void put(std::string const &key)
std::string to_string() const
BOOST_AUTO_TEST_CASE |
( |
table_values |
| ) |
|
Definition at line 370 of file values_test.cc.
377 p1.
put<
string>(
"b",
"B");
378 p1.
put<
string>(
"a",
"A");
379 BOOST_TEST(p1.
get<
string>(
"a") ==
"A");
380 BOOST_TEST(p1.
get<
string>(
"b") ==
"B");
381 BOOST_TEST(p1.
to_string() ==
"a:\"A\" b:\"B\"");
384 p2.
put<
string>(
"y",
"Y");
385 p2.put<
string>(
"z",
"Z");
386 p2.put<
string>(
"x",
"X");
387 BOOST_TEST(p2.get<
string>(
"x") ==
"X");
388 BOOST_TEST(p2.get<
string>(
"y") ==
"Y");
389 BOOST_TEST(p2.get<
string>(
"z") ==
"Z");
390 BOOST_TEST(p2.to_string() ==
"x:\"X\" y:\"Y\" z:\"Z\"");
395 BOOST_TEST(p3.is_key_to_table(
"p2"));
396 BOOST_TEST(!p3.is_key_to_sequence(
"p2"));
397 BOOST_TEST(!p3.is_key_to_atom(
"p2"));
403 BOOST_TEST(p3.to_string() ==
404 "p1:{a:\"A\" b:\"B\"} p2:{x:\"X\" y:\"Y\" z:\"Z\"}");
T get(std::string const &key) const
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
std::string to_string() const