20 static double eps = 1.e-10;
36 cout <<
"1.." <<
iTest-1 << endl;
45 cout <<
"1.." <<
nTests << endl;
59 diag(
const std::string& msg)
61 TString
s(msg.c_str());
64 repl.Substitute(
s,
"# ",
"mg");
65 TPRegexp repl2(
"\\n$");
66 repl.Substitute(
s,
"",
"");
67 cout <<
s.Data() << endl;
71 diag(
const std::ostringstream& msg)
77 pass(
const std::string& name)
83 fail(
const std::string& name)
101 ok(
bool okay,
const std::string& name)
113 is(
const double a,
const double b)
115 return is(a, b,
string(
""));
119 is(
const double a,
const double b,
const std::string& name)
122 const double thisEps =
eps;
123 if (!(
SAMENONFINITE(a,b) || (a+thisEps > b && a-thisEps < b) )) {
128 if (retval ==
false) {
130 s <<
", Difference: test="
144 return isnot(a, b,
string(
""));
148 isnot(
const double a,
const double b,
const std::string& name)
156 if (retval ==
false) {
158 s <<
", Unexpectedly equivalent: test="
172 is(
const float a,
const float b)
173 {
return is((
double)a, (
double)b); }
176 is(
const float a,
const float b,
const std::string& name)
177 {
return is((
double)a, (
double)b, name); }
181 {
return isnot((
double)a, (
double)b); }
184 isnot(
const float a,
const float b,
const std::string& name)
185 {
return isnot((
double)a, (
double)b, name); }
188 isEps(
const double a,
const double b,
const double thisEps,
const std::string& name)
191 if (!(
SAMENONFINITE(a,b) || (a+thisEps > b && a-thisEps < b) )) {
196 if (retval ==
false) {
198 s <<
", Difference: test="
210 isEpsDiag(
const double a,
const double b,
const double thisEps,
const std::string& name)
213 if (!(
SAMENONFINITE(a,b) || (a+thisEps > b && a-thisEps < b) )) {
218 if (retval ==
false) {
220 s <<
", Difference: test="
232 isDiag(
const double a,
const double b,
const std::string& name)
240 isRelEpsDiag(
const double a,
const double b,
const double thisEps,
const std::string& name)
242 return isEpsDiag(a, b, (fabs(a+b) == 0. ? 1.e-12 : fabs(a+b)*thisEps/2.), name);
246 isDiag(
const std::vector<double>&
a,
const std::vector<double>&
b,
const std::string& name)
252 isEpsDiag(
const std::vector<double>&
a,
const std::vector<double>&
b,
const double thisEps,
const std::string& name)
255 const unsigned int na = a.size();
256 const unsigned int nb = b.size();
258 std::string nName = name + std::string(
" (vector size)");
259 if (!
isDiag(na, nb, nName))
263 for (i = 0; i < na; ++i) {
264 if (!(
SAMENONFINITE(a[i],b[i]) || (a[i]+thisEps > b[i] && a[i]-thisEps < b[i]) )) {
270 if (retval ==
false) {
275 if (retval ==
false) {
276 std::ostringstream
s;
278 s <<
", Difference at index " << i
292 isRelEpsDiag(
const std::vector<double>&
a,
const std::vector<double>&
b,
const double thisEps,
const std::string& name)
295 const unsigned int na = a.size();
296 const unsigned int nb = b.size();
298 std::string nName = name + std::string(
" (vector size)");
299 if (!
isDiag(na, nb, nName))
303 for (i = 0; i < na; ++i) {
304 const double teps = fabs(a[i]+b[i]) == 0. ? 1.e-12 : fabs(a[i]+b[i])*thisEps/2.;
305 if (!(
SAMENONFINITE(a[i],b[i]) || (a[i]+teps > b[i] && a[i]-teps < b[i]) )) {
311 if (retval ==
false) {
316 if (retval ==
false) {
317 std::ostringstream
s;
319 s <<
", Difference at index " << i
334 is(
const std::vector<double>&
a,
const std::vector<double>&
b,
const std::string& name)
337 const unsigned int na = a.size();
338 const unsigned int nb = b.size();
339 const double thisEps =
eps;
341 std::string nName = name + std::string(
" (vector size)");
342 if (!
is(na, nb, nName))
346 for (i = 0; i < na; ++i) {
347 if (!(
SAMENONFINITE(a[i],b[i]) || (a[i]+thisEps > b[i] && a[i]-thisEps < b[i]) )) {
353 if (retval ==
false) {
365 if (name.length() == 0)
367 return string(
" - ") + name;
369 return string(
" # TODO & SKIP ") +
gToDoMarkers.rbegin()->second->GetReason()
370 + string(
" (testname: ") + name + string(
")");
397 if (stat(filename.c_str(), &buffer)) {
403 cout <<
"ok " <<
iTest++ <<
todoMsg(
string(
"File ") + filename +
string(
" exists")) << endl;
414 isEpsDiag(
const TVector3&
a,
const TVector3&
b,
const double thisEps,
const std::string& name)
416 bool retval = fabs(a.x() - b.x()) < thisEps && fabs(a.y() - b.y()) < thisEps && fabs(a.z() - b.z()) < thisEps;
418 std::cout <<
"(" << a.x() <<
", " << a.y() <<
", " << a.z() <<
") != "
419 <<
"(" << b.x() <<
", " << b.y() <<
", " << b.z() <<
"), "
427 s <<
", Diference (" << a.x() - b.x() <<
", " << a.y() - b.y() <<
", " << a.z() - b.z() <<
") != ";
std::string todoMsg(const std::string &name)
bool isnot(const double a, const double b)
static unsigned int iTest
bool is(const double a, const double b)
void diag(const std::string &msg)
static unsigned int gPrecision
bool isRelEpsDiag(const double a, const double b, const double thisEps, const std::string &name)
bool isEps(const double a, const double b, const double thisEps, const std::string &name)
bool fexists(const std::string &filename)
void fail(const std::string &name)
static unsigned int gCurToDoMarker
unsigned int & GetTestNo()
bool isEpsDiag(const double a, const double b, const double thisEps, const std::string &name)
static std::map< int, ToDo * > gToDoMarkers
#define SAMENONFINITE(a, b)
ToDo(const std::string reason)
bool isDiag(const double a, const double b, const std::string &name)
static unsigned int nTests
#define BOTHINFINITY(a, b)
void pass(const std::string &name)