-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestbase.hh
46 lines (32 loc) · 1.37 KB
/
testbase.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef TESTBASE_HH
#define TESTBASE_HH
#include <iostream>
#include <set>
#include <string>
#include <cmath>
using namespace std;
class TestContext { // displays test results
ostream &os; // output stream to use
int passed; // # of tests which passed
int total; // total # of tests
int lastline; // line # of most recent test
set<int> badlines; // line #'s of failed tests
bool skip; // skip a line before title?
public:
TestContext(ostream &os); // write header to stream
~TestContext(); // write summary info
void desc(const string &msg, int line); // write line/description
void check(bool test, int line); // record if a check passes
void result(); // write test result
bool ok() const; // true iff all tests passed
};
// ugly hacks
#define DESC(x) desc(x, __LINE__)
#define CHECK(test) check(test, __LINE__)
inline bool epsilon_equals(float a, float b, float epsilon = 0.00001) {
return (fabsf(a - b) <= epsilon);
}
inline bool epsilon_equals(double a, double b, double epsilon = 0.00001) {
return (fabs(a - b) <= epsilon);
}
#endif // TESTBASE_HH