11 #define BOOST_TEST_MODULE ( quantities_fhicl_test )
12 #include <boost/test/unit_test.hpp>
20 #include "fhiclcpp/types/Table.h"
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/ParameterSet.h"
25 #include <type_traits>
29 template <
typename Config>
31 fhicl::Table<Config> validatedConfig {
fhicl::Name(
"validatedConfig") };
33 std::cout << std::string(80,
'-') << std::endl;
35 if (pset.is_empty())
std::cout <<
" <empty>";
36 else std::cout <<
"\n" << pset.to_indented_string();
38 validatedConfig.print_allowed_configuration
39 (
std::cout <<
"===> Expected configuration: ");
42 validatedConfig.validate_ParameterSet(pset);
43 return validatedConfig;
48 template <
typename Config>
50 auto pset = fhicl::ParameterSet::make(configStr);
51 return validateConfig<Config>(pset);
60 using namespace std::string_view_literals;
61 using namespace util::quantities::time_literals;
64 auto t = util::quantities::makeQuantity<microsecond>(
"-7e1 ms"sv);
65 static_assert(std::is_same_v<decltype(t),
microsecond>);
66 BOOST_TEST(t == -70000_us);
67 BOOST_TEST(t == -70_ms);
69 t = util::quantities::makeQuantity<microsecond>(
"7e1ms"sv);
70 BOOST_TEST(t == 70000_us);
71 BOOST_TEST(t == 70_ms);
73 t = util::quantities::makeQuantity<microsecond>(
"7e1"sv,
true);
74 BOOST_TEST(t == 70_us);
77 util::quantities::makeQuantity<microsecond>(
"7e1"sv),
82 util::quantities::makeQuantity<microsecond>(
"7g ms"sv),
87 util::quantities::makeQuantity<microsecond>(
"g7 ms"sv),
92 util::quantities::makeQuantity<microsecond>(
""sv),
97 util::quantities::makeQuantity<microsecond>(
""sv,
true),
107 using namespace util::quantities::time_literals;
112 fhicl::Atom<util::quantities::microsecond> start
115 fhicl::Atom<util::quantities::microsecond>
end
120 std::string
const configStr {
"end: 16ms" };
124 auto validatedConfig = validateConfig<Config>(configStr)();
125 BOOST_TEST(validatedConfig.start() == expectedStart);
126 BOOST_TEST(validatedConfig.end() == expectedEnd);
134 using namespace util::quantities::time_literals;
139 fhicl::Atom<util::quantities::microsecond> start
142 fhicl::Atom<util::quantities::microsecond>
end
147 fhicl::ParameterSet pset;
152 auto validatedConfig = validateConfig<Config>(pset)();
153 BOOST_TEST(validatedConfig.start() == expectedStart);
154 BOOST_TEST(validatedConfig.end() == expectedEnd);
void test_writeQuantity()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
fhicl::Table< Config > validateConfig(std::string const &configStr)
Utilities to read and write quantities in FHiCL configuration.
A value measured in the specified unit.
auto end(FixedBins< T, C > const &) noexcept
BEGIN_PROLOG vertical distance to the surface Name
String representing a quantity has no unit.
Dimensioned variables representing space or time quantities.
String representing a quantity has an invalid number.
BEGIN_PROLOG could also be cout