Repository navigation
Expand file tree
/
Copy pathtest_header.cpp
More file actions
56 lines (49 loc) · 1.58 KB
/
Copy pathtest_header.cpp
File metadata and controls
56 lines (49 loc) · 1.58 KB
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
bool ANY_FAILED = false;
template <class T>
void assert_equal(T expected, T actual, bool kill = false) {
if (!(expected == actual)) {
ANY_FAILED = true;
cout << "Assertion failed:" << endl;
cout << "Expected: " << expected << endl;
cout << " Actual: " << actual << endl;
if (kill) assert(false);
}
}
template <class T>
void assert_not_equal(T not_expected, T actual, bool kill = false) {
if (not_expected == actual) {
ANY_FAILED = true;
cout << "Assertion failed:" << endl;
cout << "Not expected: " << not_expected << endl;
cout << " Actual: " << actual << endl;
if (kill) assert(false);
}
}
void assert_true(bool actual, bool kill = false) {
if (true != actual) {
ANY_FAILED = true;
cout << "Assertion failed:" << endl;
cout << "Expected: " << "true" << endl;
cout << " Actual: " << "false" << endl;
if (kill) assert(false);
}
}
void assert_false(bool actual, bool kill = false) {
if (false != actual) {
ANY_FAILED = true;
cout << "Assertion failed:" << endl;
cout << "Expected: " << "false" << endl;
cout << " Actual: " << "true" << endl;
assert(false);
if (kill) assert(false);
}
}
void assert_almost_equal(double a, double b, double eps = 1e-9, bool kill = false) {
assert_true(abs(a - b) < eps, kill);
}
double randdouble(double a, double b) {
return static_cast<double>(rand()) / RAND_MAX * (b - a) + a;
}
int randint(int a, int b) {
return static_cast<int>(randdouble(a, b) + 0.5);
}