-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.h
63 lines (52 loc) · 1.37 KB
/
test.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
62
63
#pragma once
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include "utility.h"
namespace cz {
template <class T>
void __EXPECT_EQ(bool is_ok, T actual, T expect) {
if (!is_ok) {
std::cout << "Expect: " << std::fixed << std::setprecision(10) << expect
<< std::endl;
std::cout << "Actual: " << std::fixed << std::setprecision(10) << actual
<< std::endl;
assert(false);
}
}
template <class T>
void __EXPECT_NE(bool is_ok, T actual, T expect) {
if (!is_ok) {
std::cout << "Expect not: " << std::fixed << std::setprecision(10) << expect
<< std::endl;
std::cout << "Actual: " << std::fixed << std::setprecision(10) << actual
<< std::endl;
assert(false);
}
}
void EXPECT_EQ(const std::string& e, const char* a) {
std::string sa(a);
__EXPECT_EQ(IsEq(e, sa), e, sa);
}
template <class T>
void EXPECT_EQ(T e, T a) {
__EXPECT_EQ(IsEq(e, a), e, a);
}
template <class T>
void EXPECT_NE(T e, T a) {
__EXPECT_NE(!IsEq(e, a), e, a);
}
template <class T>
void EXPECT_LE(T a, T b) {
if (!(a <= b)) {
std::cout << "Expect: " << a << " <= " << b << std::endl;
assert(false);
}
}
#define RUN_TEST(test_name) \
printf("Testing %s\n", #test_name); \
test_name(); \
printf("Passed %s\n", #test_name);
} // namespace cz