Macros | Typedefs | Functions
to_indented_string_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "fhiclcpp/ParameterSet.h"
#include <numeric>
#include <string>
#include <vector>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (to_indented_string test)
 

Typedefs

using ints = std::vector< int >
 
using nested_ints = std::vector< ints >
 

Functions

 BOOST_AUTO_TEST_CASE (atoms)
 
 BOOST_AUTO_TEST_CASE (sequences)
 
 BOOST_AUTO_TEST_CASE (tables)
 
 BOOST_AUTO_TEST_CASE (combo)
 
 BOOST_AUTO_TEST_CASE (sequence_printout)
 
 BOOST_AUTO_TEST_CASE (nested_sequence_printout_empty)
 
 BOOST_AUTO_TEST_CASE (nested_sequence_printout)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (to_indented_string test)

Definition at line 7 of file to_indented_string_test.cc.

Typedef Documentation

using ints = std::vector<int>

Definition at line 19 of file to_indented_string_test.cc.

Definition at line 20 of file to_indented_string_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( atoms  )

Definition at line 28 of file to_indented_string_test.cc.

29 {
30  ParameterSet pset;
31  BOOST_TEST(pset.is_empty());
32  BOOST_TEST(to_ind_str(pset) == "");
33 
34  pset.put<std::string>("a", "string1");
35  BOOST_TEST(to_ind_str(pset) == "a: \"string1\"\n");
36 
37  pset.put<int>("b", -1234);
38  BOOST_TEST(to_ind_str(pset) == "a: \"string1\"\n"
39  "b: -1234\n");
40 
41  pset.put<bool>("c", false);
42  BOOST_TEST(to_ind_str(pset) == "a: \"string1\"\n"
43  "b: -1234\n"
44  "c: false\n");
45 }
std::string string
Definition: nybbler.cc:12
bool is_empty() const
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( sequences  )

Definition at line 47 of file to_indented_string_test.cc.

48 {
49  ParameterSet pset;
50  pset.put<ints>("a", {});
51  BOOST_TEST(to_ind_str(pset) == "a: []\n");
52 
53  pset.put<ints>("b", {11});
54  BOOST_TEST(to_ind_str(pset) == "a: []\n"
55  "b: [\n"
56  " 11\n"
57  "]\n");
58 
59  pset.put<ints>("c", {11, 12, 13});
60  BOOST_TEST(to_ind_str(pset) == "a: []\n"
61  "b: [\n"
62  " 11\n"
63  "]\n"
64  "c: [\n"
65  " 11,\n"
66  " 12,\n"
67  " 13\n"
68  "]\n");
69 }
std::vector< int > ints
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( tables  )

Definition at line 71 of file to_indented_string_test.cc.

72 {
73  ParameterSet pset;
74 
76  pset.put<ParameterSet>("p1", p);
77  BOOST_TEST(to_ind_str(pset) == "p1: {}\n");
78 
79  p.put<std::string>("a", "string1");
80  pset.put<ParameterSet>("p2", p);
81  BOOST_TEST(to_ind_str(pset) == "p1: {}\n"
82  "p2: {\n"
83  " a: \"string1\"\n"
84  "}\n");
85 
86  p.put<int>("b", -1234);
87  pset.put<ParameterSet>("p3", p);
88  BOOST_TEST(to_ind_str(pset) == "p1: {}\n"
89  "p2: {\n"
90  " a: \"string1\"\n"
91  "}\n"
92  "p3: {\n"
93  " a: \"string1\"\n"
94  " b: -1234\n"
95  "}\n");
96 
97  p.put<bool>("c", false);
98  pset.put<ParameterSet>("p4", p);
99  BOOST_TEST(to_ind_str(pset) == "p1: {}\n"
100  "p2: {\n"
101  " a: \"string1\"\n"
102  "}\n"
103  "p3: {\n"
104  " a: \"string1\"\n"
105  " b: -1234\n"
106  "}\n"
107  "p4: {\n"
108  " a: \"string1\"\n"
109  " b: -1234\n"
110  " c: false\n"
111  "}\n");
112 }
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( combo  )

Definition at line 114 of file to_indented_string_test.cc.

115 {
116  ParameterSet p;
117  p.put<ints>("v", {11, 12, 13});
118 
119  ParameterSet pset;
120  pset.put<ParameterSet>("p", p);
121  BOOST_TEST(to_ind_str(pset) == "p: {\n"
122  " v: [\n"
123  " 11,\n"
124  " 12,\n"
125  " 13\n"
126  " ]\n"
127  "}\n");
128 }
std::vector< int > ints
p
Definition: test.py:223
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( sequence_printout  )

Definition at line 130 of file to_indented_string_test.cc.

131 {
132  ints v(20, 0);
133  std::iota(v.begin(), v.end(), 1);
134 
135  ParameterSet p;
136  p.put<ints>("v", v);
137 
138  ParameterSet pset;
139  pset.put<ParameterSet>("p", p);
140  BOOST_TEST(to_ind_str(pset) == "p: {\n"
141  " v: [\n"
142  " 1,\n"
143  " 2,\n"
144  " 3,\n"
145  " 4,\n"
146  " 5,\n"
147  " 6,\n"
148  " 7,\n"
149  " 8,\n"
150  " 9,\n"
151  " 10,\n"
152  " 11,\n"
153  " 12,\n"
154  " 13,\n"
155  " 14,\n"
156  " 15,\n"
157  " 16,\n"
158  " 17,\n"
159  " 18,\n"
160  " 19,\n"
161  " 20\n"
162  " ]\n"
163  "}\n");
164 }
std::vector< int > ints
p
Definition: test.py:223
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( nested_sequence_printout_empty  )

Definition at line 166 of file to_indented_string_test.cc.

167 {
168  nested_ints nested;
169  ParameterSet p;
170  p.put<nested_ints>("empty", nested);
171 
172  ParameterSet pset;
173  pset.put<ParameterSet>("p", p);
174  BOOST_TEST(to_ind_str(pset) == "p: {\n"
175  " empty: []\n"
176  "}\n");
177 }
std::vector< ints > nested_ints
p
Definition: test.py:223
void put(std::string const &key)
BOOST_AUTO_TEST_CASE ( nested_sequence_printout  )

Definition at line 179 of file to_indented_string_test.cc.

180 {
181  ints v(4, 0);
182  std::iota(v.begin(), v.end(), 1);
183  nested_ints nested{v};
184 
185  v.push_back(5);
186  nested.push_back(v);
187  ParameterSet p;
188  p.put<nested_ints>("nested", nested);
189 
190  ParameterSet pset;
191  pset.put<ParameterSet>("p", p);
192  BOOST_TEST(to_ind_str(pset) == "p: {\n"
193  " nested: [\n"
194  " [\n"
195  " 1,\n"
196  " 2,\n"
197  " 3,\n"
198  " 4\n"
199  " ],\n"
200  " [\n"
201  " 1,\n"
202  " 2,\n"
203  " 3,\n"
204  " 4,\n"
205  " 5\n"
206  " ]\n"
207  " ]\n"
208  "}\n");
209 }
std::vector< ints > nested_ints
std::vector< int > ints
p
Definition: test.py:223
void put(std::string const &key)