Macros | Functions
quantities_fhicl_test.cc File Reference

Unit test for quantities_fhicl.h header. More...

#include <boost/test/unit_test.hpp>
#include "lardataalg/Utilities/quantities/spacetime.h"
#include "lardataalg/Utilities/quantities_fhicl.h"
#include "test/Utilities/disable_boost_fpc_tolerance.hpp"
#include "fhiclcpp/types/Table.h"
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/ParameterSet.h"
#include <type_traits>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( quantities_fhicl_test )
 

Functions

template<typename Config >
fhicl::Table< ConfigvalidateConfig (fhicl::ParameterSet const &pset)
 
template<typename Config >
fhicl::Table< ConfigvalidateConfig (std::string const &configStr)
 
void test_makeQuantity ()
 
void test_readQuantity ()
 
void test_writeQuantity ()
 
 BOOST_AUTO_TEST_CASE (quantities_testcase)
 
 BOOST_AUTO_TEST_CASE (quantities_fhicl_testcase)
 

Detailed Description

Unit test for quantities_fhicl.h header.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
November 27, 2019
See also
lardataalg/Utilities/quantities_fhicl.h

Definition in file quantities_fhicl_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( quantities_fhicl_test )

Definition at line 11 of file quantities_fhicl_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( quantities_testcase  )

Definition at line 162 of file quantities_fhicl_test.cc.

162  {
163 
165 
166 } // BOOST_AUTO_TEST_CASE(quantities_testcase)
void test_makeQuantity()
BOOST_AUTO_TEST_CASE ( quantities_fhicl_testcase  )

Definition at line 169 of file quantities_fhicl_test.cc.

169  {
170 
173 
174 } // BOOST_AUTO_TEST_CASE(quantities_fhicl_testcase)
void test_writeQuantity()
void test_readQuantity()
void test_makeQuantity ( )

Definition at line 58 of file quantities_fhicl_test.cc.

58  {
59 
60  using namespace std::string_view_literals;
61  using namespace util::quantities::time_literals;
63 
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);
68 
69  t = util::quantities::makeQuantity<microsecond>("7e1ms"sv);
70  BOOST_TEST(t == 70000_us);
71  BOOST_TEST(t == 70_ms);
72 
73  t = util::quantities::makeQuantity<microsecond>("7e1"sv, true);
74  BOOST_TEST(t == 70_us);
75 
76  BOOST_CHECK_THROW(
77  util::quantities::makeQuantity<microsecond>("7e1"sv),
79  );
80 
81  BOOST_CHECK_THROW(
82  util::quantities::makeQuantity<microsecond>("7g ms"sv),
84  );
85 
86  BOOST_CHECK_THROW(
87  util::quantities::makeQuantity<microsecond>("g7 ms"sv),
89  );
90 
91  BOOST_CHECK_THROW(
92  util::quantities::makeQuantity<microsecond>(""sv),
94  );
95 
96  BOOST_CHECK_THROW(
97  util::quantities::makeQuantity<microsecond>(""sv, true),
99  );
100 
101 } // test_makeQuantity()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
String representing a quantity has spurious characters after the number.
Definition: quantities.h:1108
Literal constants for time quantities.
Definition: spacetime.h:175
String representing a quantity has no unit.
Definition: quantities.h:1092
String representing a quantity has an invalid number.
Definition: quantities.h:1104
void test_readQuantity ( )

Definition at line 105 of file quantities_fhicl_test.cc.

105  {
106 
107  using namespace util::quantities::time_literals;
109 
110  struct Config {
111 
113  { fhicl::Name("start"), 0_us };
114 
116  { fhicl::Name("end"), 6_ms };
117 
118  }; // struct Config
119 
120  std::string const configStr { "end: 16ms" };
121  util::quantities::microsecond const expectedStart = 0_us;
122  util::quantities::microsecond const expectedEnd = 16_ms;
123 
124  auto validatedConfig = validateConfig<Config>(configStr)();
125  BOOST_TEST(validatedConfig.start() == expectedStart);
126  BOOST_TEST(validatedConfig.end() == expectedEnd);
127 
128 } // test_readQuantity()
std::string string
Definition: nybbler.cc:12
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
ChannelGroupService::Name Name
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
A value measured in the specified unit.
Definition: quantities.h:566
Literal constants for time quantities.
Definition: spacetime.h:175
void test_writeQuantity ( )

Definition at line 132 of file quantities_fhicl_test.cc.

132  {
133 
134  using namespace util::quantities::time_literals;
136 
137  struct Config {
138 
140  { fhicl::Name("start"), 0_us };
141 
143  { fhicl::Name("end"), 6_ms };
144 
145  }; // struct Config
146 
147  fhicl::ParameterSet pset;
148  pset.put<util::quantities::microsecond>("end", 16_ms);
149  util::quantities::microsecond const expectedStart = 0_us;
150  util::quantities::microsecond const expectedEnd = 16_ms;
151 
152  auto validatedConfig = validateConfig<Config>(pset)();
153  BOOST_TEST(validatedConfig.start() == expectedStart);
154  BOOST_TEST(validatedConfig.end() == expectedEnd);
155 
156 } // test_writeQuantity()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
ChannelGroupService::Name Name
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
A value measured in the specified unit.
Definition: quantities.h:566
Literal constants for time quantities.
Definition: spacetime.h:175
void put(std::string const &key)
template<typename Config >
fhicl::Table<Config> validateConfig ( fhicl::ParameterSet const &  pset)

Definition at line 30 of file quantities_fhicl_test.cc.

30  {
31  fhicl::Table<Config> validatedConfig { fhicl::Name("validatedConfig") };
32 
33  std::cout << std::string(80, '-') << std::endl;
34  std::cout << "===> FHiCL configuration:";
35  if (pset.is_empty()) std::cout << " <empty>";
36  else std::cout << "\n" << pset.to_indented_string();
37  std::cout << std::endl;
38  validatedConfig.print_allowed_configuration
39  (std::cout << "===> Expected configuration: ");
40  std::cout << std::endl;
41 
42  validatedConfig.validate_ParameterSet(pset);
43  return validatedConfig;
44 } // validateConfig()
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
QTextStream & endl(QTextStream &s)
template<typename Config >
fhicl::Table<Config> validateConfig ( std::string const &  configStr)

Definition at line 49 of file quantities_fhicl_test.cc.

49  {
50  auto pset = fhicl::ParameterSet::make(configStr);
51  return validateConfig<Config>(pset);
52 } // validateConfig(Config)
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68