cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Test.h File Reference
#include <cmath>
#include "CepGen/Core/Exception.h"
#include "CepGen/Utils/String.h"
+ Include dependency graph for Test.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  cepgen
 Common namespace for this Monte Carlo generator.
 
namespace  cepgen::test
 

Macros

#define CG_FAILED(name)
 
#define CG_PASSED(name)   CG_LOG << cepgen::utils::colourise("Passed ", cepgen::utils::Colour::green) << name << "."
 
#define CG_TEST_DEBUG(debugging)   cepgen::test::debug = debugging
 
#define CG_TEST_SET_FAILURE_TOLERANCE_RATE(tolerance)   cepgen::test::failure_tolerance = tolerance
 
#define CG_TEST_SET_PRECISION(precis)   cepgen::test::precision = precis
 
#define CG_TEST_RESET_PRECISION()   cepgen::test::precision = cepgen::test::base_precision
 
#define CG_TEST(test_cond, name)
 
#define CG_TEST_EQUAL(var1, var2, name)
 
#define CG_TEST_EQUIV(var1, var2, name)
 
#define CG_TEST_UNCERT(diff, unc, nsigma, name)
 
#define CG_TEST_VALUES(val1, val2, nsigma, name)
 
#define CG_TEST_EXCEPT(sequence, name)
 
#define CG_TEST_SUMMARY
 

Variables

bool debug = false
 
double failure_tolerance = 0.
 
const double base_precision = 1.e-3
 
double precision = base_precision
 
size_t num_total = 0
 
size_t num_passed = 0
 

Macro Definition Documentation

◆ CG_FAILED

#define CG_FAILED (   name)
Value:
<< "!"
#define CG_LOG
Definition Message.h:212
std::string colourise(const std::string &str, const Colour &col, const Modifier &mod)
Colourise a string for TTY-type output streams.
Definition String.cpp:70

Definition at line 20 of file Test.h.

◆ CG_PASSED

#define CG_PASSED (   name)    CG_LOG << cepgen::utils::colourise("Passed ", cepgen::utils::Colour::green) << name << "."

Definition at line 23 of file Test.h.

◆ CG_TEST

#define CG_TEST (   test_cond,
  name 
)
Value:
{ \
<< "\tcondition: " << cepgen::utils::boldify(#test_cond) << "."; \
if (!(test_cond)) \
CG_FAILED(name); \
else { \
CG_PASSED(name); \
} \
}
size_t num_passed
Definition Test.h:16
bool debug
Definition Test.h:11
size_t num_total
Definition Test.h:15
std::string boldify(std::string str)
String implementation of the boldification procedure.
Definition String.cpp:49

Definition at line 30 of file Test.h.

◆ CG_TEST_DEBUG

#define CG_TEST_DEBUG (   debugging)    cepgen::test::debug = debugging

Definition at line 25 of file Test.h.

◆ CG_TEST_EQUAL

#define CG_TEST_EQUAL (   var1,
  var2,
  name 
)
Value:
{ \
<< "\tvariable 1(" << cepgen::utils::boldify(#var1) << "): " << var1 << "\n" \
<< "\tvariable 2(" << cepgen::utils::boldify(#var2) << "): " << var2 << "."; \
if ((var1) != (var2)) \
CG_FAILED(name) << " " << var1 << " != " << var2 << "."; \
else { \
CG_PASSED(name); \
} \
}

Definition at line 45 of file Test.h.

◆ CG_TEST_EQUIV

#define CG_TEST_EQUIV (   var1,
  var2,
  name 
)
Value:
{ \
if (std::fabs((var1) - (var2)) > cepgen::test::precision) \
CG_FAILED(name) << " " << var1 << " is not within " << cepgen::test::precision << " of " << var2 << "."; \
else { \
CG_PASSED(name); \
} \
}
double precision
Definition Test.h:14

Definition at line 61 of file Test.h.

◆ CG_TEST_EXCEPT

#define CG_TEST_EXCEPT (   sequence,
  name 
)
Value:
<< "\tsequence: " << cepgen::utils::boldify(#sequence) << "."; \
try { \
sequence(); \
throw cepgen::Exception("", "this_test"); \
} catch (const cepgen::Exception& exc) { \
if (exc.from() == "this_test") \
CG_FAILED(name); \
else { \
CG_PASSED(name) << " Resulting exception:\n" \
} \
}
const std::string & from() const
Origin of the exception.
Definition Message.h:161
std::string message() const
Human-readable message.
Definition Message.h:158

Definition at line 106 of file Test.h.

◆ CG_TEST_RESET_PRECISION

#define CG_TEST_RESET_PRECISION ( )    cepgen::test::precision = cepgen::test::base_precision

Definition at line 28 of file Test.h.

◆ CG_TEST_SET_FAILURE_TOLERANCE_RATE

#define CG_TEST_SET_FAILURE_TOLERANCE_RATE (   tolerance)    cepgen::test::failure_tolerance = tolerance

Definition at line 26 of file Test.h.

◆ CG_TEST_SET_PRECISION

#define CG_TEST_SET_PRECISION (   precis)    cepgen::test::precision = precis

Definition at line 27 of file Test.h.

◆ CG_TEST_SUMMARY

◆ CG_TEST_UNCERT

#define CG_TEST_UNCERT (   diff,
  unc,
  nsigma,
  name 
)
Value:
{ \
<< "\tdifference: " << diff << ", sigma: " << unc << " = " << diff / unc << " * sigma " \
<< ((diff > nsigma * unc) ? ">" : "<") << " " << nsigma << " * sigma."; \
if (unc > 0 && diff > nsigma * unc) \
CG_FAILED(name) << " difference " << diff << " is not within " << nsigma << " sigmas=" << unc << "."; \
else { \
CG_PASSED(name); \
} \
}

Definition at line 72 of file Test.h.

◆ CG_TEST_VALUES

#define CG_TEST_VALUES (   val1,
  val2,
  nsigma,
  name 
)
Value:
{ \
const auto diff = cepgen::Value(val1) - cepgen::Value(val2); \
<< "\tvals: " << val1 << ", " << val2 << ", difference: " << (val1 - val2) \
<< ", sigma: " << diff.uncertainty() << " = " << diff.relativeUncertainty() << " * sigma " \
<< ((std::fabs(1. / diff.relativeUncertainty()) > nsigma) ? ">" : "<") << " " << nsigma << " * sigma."; \
if (diff.uncertainty() > 0 && diff > nsigma * diff.uncertainty()) \
CG_FAILED(name) << " difference " << diff << " is not within " << nsigma << " sigmas."; \
else { \
CG_PASSED(name); \
} \
}
A scalar value with its uncertainty.
Definition Value.h:26

Definition at line 88 of file Test.h.