All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
KeyValueParser_test.cc File Reference

Unit test icarus::details::KeyValueParser More...

#include "icaruscode/PMT/Algorithms/KeyValueParser.h"
#include "icaruscode/Decode/DecoderTools/details/KeyValuesData.h"
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <sstream>
#include <vector>
#include <array>
#include <string>
#include <cstdint>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( KeyValueParser_test )
 

Functions

void SPR_test ()
 
 BOOST_AUTO_TEST_CASE (parse_testcase)
 

Detailed Description

Unit test icarus::details::KeyValueParser

Date
May 18, 2022
Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
See Also
icaruscode/PMT/Algorithms/KeyValueParser.h

Definition in file KeyValueParser_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( KeyValueParser_test )

Definition at line 15 of file KeyValueParser_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( parse_testcase  )

Definition at line 114 of file KeyValueParser_test.cc.

114  {
115 
116  SPR_test();
117 
118 } // BOOST_AUTO_TEST_CASE(parse_testcase)
void SPR_test()
void SPR_test ( )

Definition at line 30 of file KeyValueParser_test.cc.

30  {
31 
32  std::string const info { R"( # SPR test input file Description: " This is a test for the key-values parser with default settings. It is expected to be used to describe the Single Photoelectron Response. " Contact: Gianluca Petrillo (petrillo@slac.stanford.edu) Gain: 9.7e6 # from amplitude 4 mV Tick: '2 ns' Samples: 0.0 1.0 2.5 \ 4.5 3.0 2.5 Samples:+1.8 1.6 1.2 0.8 0.8 0.7 0.7 0.6 )" };
33 
35 
36  std::istringstream in { info };
37  icarus::KeyValuesData const data { parser(in) };
38 
39  std::cout << "Input:\n" << std::string(80, '-') << "\n"
40  << info
41  << "\n" << std::string(80, '-')
42  << "\nParsed:\n" << data
43  << std::endl;
44 
45  BOOST_TEST(data.hasItem("Description"));
46  if (data.hasItem("Description")) {
47  icarus::KeyValuesData::Item const& item = data.getItem("Description");
48  BOOST_TEST(item.nValues() == 1);
49  BOOST_TEST(item.value() == "\n"
50  "This is a test for the key-values parser with default settings.\n"
51  "It is expected to be used to describe the Single Photoelectron Response.\n"
52  );
53  }
54 
55  BOOST_TEST(data.hasItem("Contact"));
56  if (data.hasItem("Contact")) {
57  icarus::KeyValuesData::Item const& item = data.getItem("Contact");
58  BOOST_TEST(item.nValues() == 3);
59  BOOST_TEST(item.value(0) == "Gianluca");
60  BOOST_TEST(item.value(1) == "Petrillo");
61  BOOST_TEST(item.value(2) == "(petrillo@slac.stanford.edu)");
62  }
63 
64  BOOST_TEST(data.hasItem("Gain"));
65  if (data.hasItem("Gain")) {
66  icarus::KeyValuesData::Item const& item = data.getItem("Gain");
67  BOOST_TEST(item.nValues() == 1);
68  BOOST_TEST
69  (item.getNumber<double>(0) == 9.7e6, boost::test_tools::tolerance(0.001));
70  }
71 
72  BOOST_TEST(data.hasItem("Tick"));
73  if (data.hasItem("Tick")) {
74  icarus::KeyValuesData::Item const& item = data.getItem("Tick");
75  BOOST_TEST(item.nValues() == 1);
76  BOOST_TEST(item.value() == "2 ns");
77  }
78 
79  BOOST_TEST(data.hasItem("Samples"));
80  if (data.hasItem("Samples")) {
81  icarus::KeyValuesData::Item const& item = data.getItem("Samples");
82  std::array const samples
83  { 0.0, 1.0, 2.5, 4.5, 3.0, 2.5, 1.8, 1.6, 1.2, 0.8, 0.8, 0.7, 0.7, 0.6 };
84  std::vector<double> const values = item.getVector<double>();
85  BOOST_CHECK_EQUAL_COLLECTIONS
86  (values.begin(), values.end(), samples.cbegin(), samples.cend());
87  BOOST_CHECK_THROW
89  }
90 
91 } // SPR_test()
92 
T getNumber(std::size_t index, unsigned int base) const
Returns the requested value, converted into a number of type T
auto const tolerance
Representation of a single item of data: a key and several values.
then echo ***************************************echo array
Definition: find_fhicl.sh:28
Collection of items with key/values structure.
std::size_t nValues() const noexcept
Returns the number of values currently present.
std::vector< T > getVector(Conv converter={}) const
Returns all the values, each converted into type T
Parser to fill a KeyValuesData structure out of a character buffer.
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
BEGIN_PROLOG could also be cout