-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.h
More file actions
53 lines (40 loc) · 2.46 KB
/
Copy pathcheck.h
File metadata and controls
53 lines (40 loc) · 2.46 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
// Simple unit test.
// Part of lvvlib - https://github.com/lvv/lvvlib
// Copyright (c) 2000-2013
// Leonid Volnitsky (Leonid@Volnitsky.com)
#ifndef LVV_CHECK_H
#define LVV_CHECK_H
#include <iostream>
using std::cout;
using std::endl;
//#include <lvv/math.h>
namespace check {
///////////////////////////////////////////////////////////////////////////////////// TEST MACROS
static __attribute__((unused)) bool all_pass=true;
static bool result=false;
#define PASS " pass "
#define FAIL ">>> FAIL <<<"
#define RESULT std::cout << (check::result ? PASS : FAIL) << " " << __LINE__ << "\t\t";
#define CHECK(e) check::result=(e); check::all_pass = check::all_pass && check::result; RESULT; std::cout << "check: \t" #e << std::endl;
/*
#define CHECK_ARE_FP_EQUAL(e1,e2) result=(eq((e1),(e2))); all_pass = (all_pass && result); RESULT; \
if (result) std::cout << "are equal: \t" << #e1 "\t == " #e2 << std::endl; \
else std::cout << "are equal: \t" << #e1 "\t == " #e2 << " (values: " << (e1) << ", " << (e2) << ")" << std::endl;
*/
#define CHECK_TYPES_ARE_SAME(T,U) check::result=std::is_same<T,U>::value; check::all_pass = (check::all_pass && check::result); RESULT; \
if (check::result) std::cout << "same: \t" << #T "\t == " #U << std::endl; \
else std::cout << "same: \t" << #T "\t == " #U << " (values: " << type2name<T>() << ", " << type2name<U>() << ")" << std::endl;
#define CHECK_ARE_EQUAL(e1,e2) check::result=((e1)==(e2)); check::all_pass = (check::all_pass && check::result); RESULT; \
if (check::result) std::cout << "are equal: \t" << #e1 "\t == " #e2 << std::endl; \
else std::cout << "are equal: \t" << #e1 "\t == " #e2 << " (values: " << (e1) << ", " << (e2) << ")" << std::endl;
#define CHECK_NOT_EQUAL(e1,e2) check::result=((e1)!=(e2)); check::all_pass = (check::all_pass && check::result); RESULT; \
if (check::result) std::cout << "are not equal: \t" << #e1 "\t != " #e2 << std::endl; \
else std::cout << "are not equal: \t" << #e1 "\t != " #e2 << " values: " << (e1) << ", " << (e2) << std::endl;
#define CHECK_EXIT \
std::cout << (check::all_pass ? "\n------------ all pass ------------\n" : "\n!!!!!!!!! SOME FAILED !!!!!!!!\n"); \
exit(check::all_pass ? 0 : 1);
// aliases
#define CHECKeq CHECK_ARE_EQUAL
#define CHECKneq CHECK_NOT_EQUAL
}; // namespace check
#endif // LVV_CHECK_H