-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helpers.h
61 lines (51 loc) · 1.21 KB
/
test_helpers.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __TEST_HELPERS__
#define __TEST_HELPERS__
#include <iostream>
class TestHelper {
public:
TestHelper() : _ok(0), _failed(0) { }
void message(const char *message) const {
std::cout << message << "... ";
}
template<typename T>
void tassert(const T& e1, const T& e2, const char *msg = nullptr, bool silent = false) {
if (e1 == e2) {
if(!silent) {
if(msg) {
std::cout << msg << "... ";
}
std::cout << tick() << std::endl;
}
_ok++;
}
else {
if(msg) {
std::cout << msg << "... ";
}
std::cout << cross()
<< " (" << "expected " << e1
<< " got " << e2 << ")" << std::endl;
_failed++;
}
}
void tassert(bool cond = true, const char *msg = nullptr) {
tassert(cond, true, msg);
}
void summary() const {
std::cout << std::endl << "*** "
<< _ok << " passed " << tick() << " "
<< _failed << " failed " << cross()
<< std::endl;
}
private:
const char *tick() const {
return "\033[32m✔\033[0m";
}
const char *cross() const {
return "\033[31m✖\033[0m";
}
private:
unsigned int _ok;
unsigned int _failed;
};
#endif