Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
16 
17 #include "IO/bridgeIO.h"
18 using Bridge::vout;
19 
20 #ifdef USE_TESTMANAGER
21 #include "testManager.h"
22 #endif
23 
24 // utility routines for verifying test result.
25 
26 namespace Test {
27  int verify(const double result, const double expected, double eps)
28  {
30 
31  int verify_result = 0; // 0 for successful, 1 for failure.
32 
33  int precision = default_precision;
34 
35 #if USE_TESTMANAGER
36  // obtain current precision specified through menu.
38 #endif
39 
40  if (fabs(eps) < CommonParameters::epsilon_criterion()) { // if eps is unspecified
41  eps = pow(10.0, -precision);
42  }
43 
44  vout.general(vl, "\n");
45  vout.general(vl, "check test data\n");
46  // vout.general(vl, "%s \n", testname.c_str());
47 
48  //vout.general(vl, "check precision = %d\n", precision);
49  vout.general(vl, "check precision = %2.1e\n", eps);
50 
51  vout.general(vl, "result: %15.14le expected: %15.14le\n", result, expected);
52 
53  double diff;
54  if (fabs(expected) > eps) {
55  diff = (result - expected) / expected;
56  } else {
57  diff = result - expected;
58  }
59 
60  if (fabs(diff) <= eps) {
61  vout.general(vl, "test result: correct! (^_^)\n");
62  verify_result = 0;
63  } else {
64  vout.general(vl, "test result: incorrect! (T_T)\n");
65  verify_result = 1;
66  }
67  vout.general(vl, "diff: expected - result = %15.14le\n", diff);
68  //vout.general(vl, "diff1: expected - result = %15.14le\n", diff);
69  //vout.general(vl, "diff2: exp(-diff) = %15.14le\n", exp(-diff));
70  vout.general(vl, "\n");
71 
72  return verify_result;
73  }
74 }
BridgeIO vout
Definition: bridgeIO.cpp:503
static double epsilon_criterion()
void general(const char *format,...)
Definition: bridgeIO.cpp:197
static Bridge::VerboseLevel Vlevel()
int getCheckPrecision() const
Definition: testManager.h:73
static const int default_precision
Definition: test.h:32
static TestManager & Instance()
Definition: testManager.cpp:41
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42