Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestSummary.hh
Go to the documentation of this file.
1 #ifndef __JCOMPAREHISTOGRAMS__JTESTSUMMARY_T__
2 #define __JCOMPAREHISTOGRAMS__JTESTSUMMARY_T__
3 
4 #include <string>
5 #include <istream>
6 #include <ostream>
7 
8 #include "Jeep/JPrint.hh"
9 #include "Jeep/JProperties.hh"
10 
11 #include "JLang/JColorFacet.hh"
12 
13 #include "JGizmo/JRootObjectID.hh"
14 
15 
16 /**
17  * \author rgruiz, bjung
18  */
19 
20 namespace JCOMPAREHISTOGRAMS {}
21 namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
22 
23 namespace JCOMPAREHISTOGRAMS {
24 
26 
27  static const char* const PASSED_t = "PASSED";
28  static const char* const FAILED_t = "FAILED";
29 
30  /**
31  * Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived classes.
32  */
34  {
35  public:
36 
37  /**
38  * Default constructor.
39  */
41  testName (""),
44  parameterName (""),
45  parameterValue (0.0),
46  parameterThreshold(0.0),
47  passed (false),
49  {}
50 
51 
52  /**
53  * Constructor
54  *
55  * \param testName Test name
56  * \param hA Name of the first histogram.
57  * \param hB Name of the second histogram.
58  * \param parameter Name of the parameter used for the test.
59  * \param threshold Threshold value for the tested parameter.
60  * \param value Value of the tested parameter.
61  * \param passed true if the test is passed; else false.
62  */
64  const JRootObjectID& hA,
65  const JRootObjectID& hB,
66  const std::string& parameter,
67  const double value,
68  const double threshold,
69  const bool passed):
70  testName (testName),
71  histogramA (hA),
72  histogramB (hB),
73  parameterName (parameter),
74  parameterValue (value),
75  parameterThreshold(threshold),
76  passed (passed),
77  passed_h (passed ? PASSED_t : FAILED_t)
78  {}
79 
80 
81  /**
82  * Get equation parameters.
83  *
84  * \return equation parameters
85  */
87  {
88  static JEquationParameters equation("=", "; ", "", "#");
89 
90  return equation;
91  }
92 
93 
94  /**
95  * Set equation parameters.
96  *
97  * \param equation equation parameters
98  */
99  static inline void setEquationParameters(const JEquationParameters& equation)
100  {
101  getEquationParameters() = equation;
102  }
103 
104 
105  /**
106  * Get properties of this class.
107  *
108  * \param equation equation parameters
109  */
111  {
112  return JTestSummaryHelper(*this, equation);
113  }
114 
115 
116  /**
117  * Get properties of this class.
118  *
119  * \param equation equation parameters
120  */
122  {
123  return JTestSummaryHelper(*this, equation);
124  }
125 
126 
127  /**
128  * Read test summary from input.
129  *
130  * \param in input stream
131  * \param object test summary
132  * \return input stream
133  */
134  friend inline std::istream& operator>>(std::istream& in,
135  JTestSummary& object)
136  {
137  using namespace std;
138 
139  in >> object.testName
140  >> object.histogramA
141  >> object.histogramB
142  >> object.parameterName
143  >> object.parameterThreshold
144  >> object.passed_h;
145 
146  object.passed = (object.passed_h == PASSED_t) ? 1 : 0;
147 
148  return in;
149  }
150 
151 
152  /**
153  * Write test summary to output.
154  *
155  * \param out output stream
156  * \param object test summary
157  * \return output stream
158  */
159  friend inline std::ostream& operator<<(std::ostream& out,
160  JTestSummary& object)
161  {
162  const JFormat format(out);
163 
164  out << object.testName << ' '
165  << object.histogramA << ' '
166  << object.histogramB << ' '
167  << object.parameterName << ' '
168  << object.parameterValue << ' '
169  << object.parameterThreshold << ' '
170  << object.passed_h;
171 
172  return out;
173  }
174 
175  std::string testName; /*!< Test name. */
176  JRootObjectID histogramA; /*!< First histogram. */
177  JRootObjectID histogramB; /*!< Second histogram. */
178  std::string parameterName; /*!< Parameter evaluated by the test. */
179  double parameterValue; /*!< Value of the parameter evaluated by the test.*/
180  double parameterThreshold; /*!< Threshold to evaluate the parameter. */
181  bool passed; /*!< True if the test passed. */
182  std::string passed_h; /*!< Human readable version of passed. */
183 
184  private:
185  /**
186  * Auxiliary class for I/O of test result message
187  */
189  public JProperties
190  {
191  public:
192  /**
193  * Constructor.
194  *
195  * \param object test result message
196  * \param equation equation parameters
197  */
198  template<class JTestSummary_t>
199  JTestSummaryHelper(JTestSummary_t& object,
200  const JEquationParameters& equation) :
201  JProperties(equation, 1)
202  {
203  insert(gmake_property(object.testName));
204  insert(gmake_property(object.histogramA));
205  insert(gmake_property(object.histogramB));
206  insert(gmake_property(object.parameterName));
207  insert(gmake_property(object.parameterValue));
208  insert(gmake_property(object.parameterThreshold));
209  insert(gmake_property(object.passed_h));
210  }
211  };
212  };
213 
214 
215  /**
216  * Read test summary.
217  *
218  * \param in input stream
219  * \param summary test summary
220  * \param delimiter delimiter
221  */
222  inline std::istream& read(std::istream& in,
223  JTestSummary& summary,
224  const char delimiter = ' ')
225  {
226  using namespace std;
227  using namespace JPP;
228 
229  JProperties properties = summary.getProperties();
230 
231  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
232 
233  string buffer;
234  getline(in, buffer, delimiter);
235 
236  istringstream iss(buffer);
237 
238  i->second->read(iss);
239  }
240 
241  summary.passed = (summary.passed_h == PASSED_t);
242 
243  return in;
244  }
245 
246 
247  /**
248  * Print test summary.
249  *
250  * \param out output stream
251  * \param summary test summary
252  * \param delimiter delimiter
253  * \param useColors
254  */
255  inline std::ostream& print(std::ostream& out,
256  const JTestSummary& summary,
257  const char delimiter = ' ',
258  const bool useColors = true)
259  {
260  using namespace std;
261  using namespace JPP;
262 
263  out << scientific << setprecision(2);
264 
265  if (useColors) {
266  out << (summary.passed ? GREEN : RED);
267  }
268 
269  const JProperties& properties = summary.getProperties();
270 
271  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
272  out << i->second.toString() << delimiter;
273  }
274 
275  out << RESET << endl;
276 
277  return out;
278  }
279 
280 
281  /**
282  * Print test summary.
283  *
284  * \param out output stream
285  * \param summary test summary
286  * \param __begin begin list of keys
287  * \param __end end list of keys
288  * \param delimiter delimiter
289  * \param useColors
290  */
291  template<class T>
292  inline std::ostream& print(std::ostream& out,
293  const JTestSummary& summary,
294  T __begin,
295  T __end,
296  const char delimiter = ' ',
297  const bool useColors = true)
298  {
299  using namespace std;
300  using namespace JPP;
301 
302  out << scientific << setprecision(2);
303 
304  if (useColors) {
305  out << (summary.passed ? GREEN : RED);
306  }
307 
308  for (T i = __begin; i != __end; ++i) {
309 
310  summary.getProperties()[*i]->write(out);
311 
312  out << delimiter;
313  }
314 
315  out << endl;
316 
317  return out;
318  }
319 }
320 
321 #endif
friend std::istream & operator>>(std::istream &in, JTestSummary &object)
Read test summary from input.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Definition: JTestSummary.hh:86
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
JTestSummaryHelper(JTestSummary_t &object, const JEquationParameters &equation)
Constructor.
friend std::ostream & operator<<(std::ostream &out, JTestSummary &object)
Write test summary to output.
Utility class to parse parameter values.
Definition: JProperties.hh:496
Simple data structure to support I/O of equations (see class JLANG::JEquation).
static const char *const PASSED_t
Definition: JTestSummary.hh:27
Auxiliary class to handle file name, ROOT directory and object name.
Utility class to parse parameter values.
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters())
Get properties of this class.
I/O formatting auxiliaries.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
Definition: JProperties.hh:845
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
Definition: JTestSummary.hh:99
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static const char *const FAILED_t
Definition: JTestSummary.hh:28
then awk string
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
Auxiliary class for I/O of test result message.
print
Definition: JConvertDusj.sh:44
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTestSummary.hh:33
JTestSummary(const std::string &testName, const JRootObjectID &hA, const JRootObjectID &hB, const std::string &parameter, const double value, const double threshold, const bool passed)
Constructor.
Definition: JTestSummary.hh:63
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters()) const
Get properties of this class.
JTestSummary()
Default constructor.
Definition: JTestSummary.hh:40