Macros | Functions
MultipleChoiceSelection_test.cc File Reference

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

#include <boost/test/unit_test.hpp>
#include "lardataalg/Utilities/MultipleChoiceSelection.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( MultipleChoiceSelection_test )
 

Functions

void MultipleChoiceSelection_test ()
 
 BOOST_AUTO_TEST_CASE (MultipleChoiceSelection_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 MultipleChoiceSelection_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( MultipleChoiceSelection_test )

Definition at line 11 of file MultipleChoiceSelection_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( MultipleChoiceSelection_testcase  )

Definition at line 119 of file MultipleChoiceSelection_test.cc.

119  {
120 
122 
123 } // BOOST_AUTO_TEST_CASE(MultipleChoiceSelection_testcase)
void MultipleChoiceSelection_test()
void MultipleChoiceSelection_test ( )

Definition at line 23 of file MultipleChoiceSelection_test.cc.

23  {
24 
25  enum class Color { white, gray, black, blue };
26 
27  using OptionSelector_t = util::MultipleChoiceSelection<Color>;
28 
29  OptionSelector_t options {
30  { Color::black, "black" },
31  { Color::gray, "gray", "grey" }
32  };
33 
34  BOOST_TEST(options.size() == 2U);
35 
36  BOOST_CHECK_THROW(
37  options.addAlias(Color::white, "blanche"), // Color::white not yet added
38  OptionSelector_t::UnknownOptionError
39  );
40 
41  auto const& opWhite0 = options.addOption(Color::white, "white");
42  auto const& opWhite0again = options.addAlias(Color::white, "blanche");
43  BOOST_TEST(&opWhite0again == &opWhite0);
44  BOOST_TEST(options.size() == 3U);
45 
46  std::cout << "Options:\n" << options.optionListDump(" * ") << std::endl;
47 
48  BOOST_TEST( options.hasOption(Color::white));
49  BOOST_TEST( options.hasOption(Color::gray));
50  BOOST_TEST(!options.hasOption(Color::blue));
51  BOOST_TEST( options.hasOption("white"));
52  BOOST_TEST( options.hasOption("blanche"));
53  BOOST_TEST( options.hasOption("wHite"));
54  BOOST_TEST(!options.hasOption("blue"));
55 
56  //
57  // white
58  //
59  BOOST_TEST(options.hasOption(opWhite0));
60 
61  auto const opWhite1 = options.parse("white");
62  static_assert(std::is_same_v
63  <std::decay_t<decltype(opWhite1)>, OptionSelector_t::Option_t>
64  );
65  BOOST_TEST((opWhite1 == Color::white));
66  BOOST_TEST(opWhite1 == "white");
67  BOOST_TEST(opWhite1 == opWhite0);
68 
69  auto const opWhite2 = options.parse("blanche");
70  static_assert(std::is_same_v
71  <std::decay_t<decltype(opWhite2)>, OptionSelector_t::Option_t>
72  );
73  BOOST_TEST((opWhite2 == Color::white));
74  BOOST_TEST(opWhite2 == "white");
75  BOOST_TEST(opWhite2 == "blanche");
76  BOOST_TEST(opWhite2 == "Blanche");
77  BOOST_TEST(opWhite2 == opWhite0);
78 
79  auto const opWhite3 = options.get("white");
80  static_assert(std::is_same_v
81  <std::decay_t<decltype(opWhite1)>, OptionSelector_t::Option_t>
82  );
83  BOOST_TEST(opWhite3 == "white");
84 
85  //
86  // gray
87  //
88  auto const opGray0 = options.get("gray");
89  static_assert(std::is_same_v
90  <std::decay_t<decltype(opWhite1)>, OptionSelector_t::Option_t>
91  );
92  BOOST_TEST(opWhite0 == "white");
93 
94  auto const opGray1 = options.parse("gray");
95  static_assert(std::is_same_v
96  <std::decay_t<decltype(opWhite1)>, OptionSelector_t::Option_t>
97  );
98  BOOST_TEST((opGray1 == Color::gray));
99  BOOST_TEST(opGray1 == "gray");
100  BOOST_TEST(opGray1 == "grey");
101  BOOST_TEST(opGray1 == opGray0);
102 
103  Color color = opGray1;
104  BOOST_TEST((color == Color::gray));
105 
106  //
107  // blue
108  //
109  BOOST_CHECK_THROW(options.get("blue"), OptionSelector_t::UnknownOptionError);
110  BOOST_CHECK_THROW
111  (options.parse("blue"), OptionSelector_t::UnknownOptionError);
112 
113 } // MultipleChoiceSelection_testcase()
Byte blue
Definition: image.cpp:32
Definition: image.cpp:28
std::size_t color(std::string const &procname)
Helper to select one among multiple choices via strings.
QTextStream & endl(QTextStream &s)