Macros | Functions
intervals_fhicl_test.cc File Reference

Unit test for intervals_fhicl.h header. More...

#include <boost/test/unit_test.hpp>
#include "lardataalg/Utilities/quantities/spacetime.h"
#include "lardataalg/Utilities/intervals_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   ( intervals_fhicl_test )
 

Functions

template<typename Config >
Config validateConfig (fhicl::ParameterSet const &pset)
 
template<typename Config >
Config validateConfig (std::string const &configStr)
 
void test_makeInterval ()
 
void test_makePoint ()
 
void test_read ()
 
void test_write ()
 
 BOOST_AUTO_TEST_CASE (intervals_testcase)
 
 BOOST_AUTO_TEST_CASE (points_testcase)
 
 BOOST_AUTO_TEST_CASE (quantities_fhicl_testcase)
 

Detailed Description

Unit test for intervals_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/intervals_fhicl.h

Definition in file intervals_fhicl_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( intervals_fhicl_test )

Definition at line 11 of file intervals_fhicl_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( intervals_testcase  )

Definition at line 217 of file intervals_fhicl_test.cc.

218 {
220 }
void test_makeInterval()
BOOST_AUTO_TEST_CASE ( points_testcase  )

Definition at line 222 of file intervals_fhicl_test.cc.

223 {
224  test_makePoint();
225 }
void test_makePoint()
BOOST_AUTO_TEST_CASE ( quantities_fhicl_testcase  )

Definition at line 227 of file intervals_fhicl_test.cc.

228 {
229  test_read();
230  test_write();
231 }
void test_write()
void test_read()
void test_makeInterval ( )

Definition at line 57 of file intervals_fhicl_test.cc.

57  {
58 
59  using namespace std::string_view_literals;
60  using namespace util::quantities::time_literals;
62 
63  auto t = util::quantities::makeInterval<microseconds>("-7e1 ms"sv);
64  static_assert(std::is_same_v<decltype(t), microseconds>);
65  BOOST_TEST(t == -70000_us);
66  BOOST_TEST(t == -70_ms);
67 
68  t = util::quantities::makeInterval<microseconds>("7e1ms"sv);
69  BOOST_TEST(t == 70000_us);
70  BOOST_TEST(t == 70_ms);
71 
72  t = util::quantities::makeInterval<microseconds>("7e1"sv, true);
73  BOOST_TEST(t == 70_us);
74 
75  BOOST_CHECK_THROW(
76  util::quantities::makeInterval<microseconds>("7e1"sv),
78  );
79 
80  BOOST_CHECK_THROW(
81  util::quantities::makeInterval<microseconds>("7g ms"sv),
83  );
84 
85  BOOST_CHECK_THROW(
86  util::quantities::makeInterval<microseconds>("g7 ms"sv),
88  );
89 
90  BOOST_CHECK_THROW(
91  util::quantities::makeInterval<microseconds>(""sv),
93  );
94 
95  BOOST_CHECK_THROW(
96  util::quantities::makeInterval<microseconds>(""sv, true),
98  );
99 
100 } // test_makeInterval()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
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_makePoint ( )

Definition at line 104 of file intervals_fhicl_test.cc.

104  {
105 
106  using namespace std::string_view_literals;
107  using namespace util::quantities::time_literals;
109 
110  auto t = util::quantities::makePoint<microsecond>("-7e1 ms"sv);
111  static_assert(std::is_same_v<decltype(t), microsecond>);
112  BOOST_TEST(t == -70000_us);
113  BOOST_TEST(t == -70_ms);
114 
115  t = util::quantities::makePoint<microsecond>("7e1ms"sv);
116  BOOST_TEST(t == 70000_us);
117  BOOST_TEST(t == 70_ms);
118 
119  t = util::quantities::makePoint<microsecond>("7e1"sv, true);
120  BOOST_TEST(t == 70_us);
121 
122  BOOST_CHECK_THROW(
123  util::quantities::makePoint<microsecond>("7e1"sv),
125  );
126 
127  BOOST_CHECK_THROW(
128  util::quantities::makePoint<microsecond>("7g ms"sv),
130  );
131 
132  BOOST_CHECK_THROW(
133  util::quantities::makePoint<microsecond>("g7 ms"sv),
135  );
136 
137  BOOST_CHECK_THROW(
138  util::quantities::makePoint<microsecond>(""sv),
140  );
141 
142  BOOST_CHECK_THROW(
143  util::quantities::makePoint<microsecond>(""sv, true),
145  );
146 
147 } // test_makePoint()
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
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
Definition: spacetime.h:328
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_read ( )

Definition at line 151 of file intervals_fhicl_test.cc.

151  {
152 
153  using namespace util::quantities::time_literals;
154 
155  struct Config {
156 
158  { fhicl::Name("start"), 0_us };
159 
161  { fhicl::Name("end"), 6_ms };
162 
164  { fhicl::Name("duration"), 6_ms };
165 
166  }; // struct Config
167 
168  std::string const configStr { "start: 2ms duration: 16ms" };
169  util::quantities::points::microsecond const expectedStart { 2_ms };
170  util::quantities::points::microsecond const expectedEnd { 6_ms };
171  util::quantities::intervals::microseconds const expectedDuration { 16_ms };
172 
173  auto validatedConfig = validateConfig<Config>(configStr);
174  BOOST_TEST(validatedConfig.start() == expectedStart);
175  BOOST_TEST(validatedConfig.end() == expectedEnd);
176  BOOST_TEST(validatedConfig.duration() == expectedDuration);
177 
178 } // test_read()
std::string string
Definition: nybbler.cc:12
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
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Literal constants for time quantities.
Definition: spacetime.h:175
void test_write ( )

Definition at line 182 of file intervals_fhicl_test.cc.

182  {
183 
184  using namespace util::quantities::time_literals;
185  struct Config {
186 
188  { fhicl::Name("start"), 0_us };
189 
191  { fhicl::Name("end"), 6_ms };
192 
194  { fhicl::Name("duration"), 6_ms };
195 
196  }; // struct Config
197 
198  util::quantities::points::microsecond const expectedStart { 2_ms };
199  util::quantities::points::microsecond const expectedEnd { 6_ms };
200  util::quantities::intervals::microseconds const expectedDuration { 16_ms };
201 
202  fhicl::ParameterSet pset;
203  pset.put("start", expectedStart);
204  pset.put("duration", expectedDuration);
205 
206  auto validatedConfig = validateConfig<Config>(pset);
207  BOOST_TEST(validatedConfig.start() == expectedStart);
208  BOOST_TEST(validatedConfig.end() == expectedEnd);
209  BOOST_TEST(validatedConfig.duration() == expectedDuration);
210 
211 } // test_write()
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
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Literal constants for time quantities.
Definition: spacetime.h:175
void put(std::string const &key)
template<typename Config >
Config validateConfig ( fhicl::ParameterSet const &  pset)

Definition at line 30 of file intervals_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 >
Config validateConfig ( std::string const &  configStr)

Definition at line 49 of file intervals_fhicl_test.cc.

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