-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tester.cpp
108 lines (94 loc) · 2.16 KB
/
Tester.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "Tester.h"
#include <string>
#include <cstring>
Tester::Tester(std::stringstream& ss): ss(ss)
{
// node();
// eig();
// cluster();
// concat();
// solveClusters();
// calAlpha();
// OutputDebugstd::string(ss.str().c_str());
}
Tester::~Tester()
{
}
bool Tester::it(const std::string des, const MatrixXd& expect, const MatrixXd& given, double esp) const
{
ss << des << ": ";
MatrixXd diff = expect - given;
if (diff.squaredNorm() < esp)
{
ss << "OK" << std::endl;
return true;
}
ss << "Error\nExpected:" << std::endl;
ss << expect << std::endl;
ss << "Found:" << std::endl;
ss << given << std::endl;
return false;
}
bool Tester::it(const std::string des, const VectorXd& expect, const VectorXd& given, double esp) const
{
ss << des << ": ";
VectorXd diff = expect - given;
if (diff.squaredNorm() < esp)
{
ss << "OK" << std::endl;
return true;
}
ss << "Error\nExpected:" << std::endl;
ss << expect << std::endl;
ss << "Found:" << std::endl;
ss << given << std::endl;
return false;
}
auto Tester::it(const std::string des, double expect, double given, double esp) -> bool
{
ss << des << ": ";
double diff = expect - given;
if (diff < esp)
{
ss << "OK" << std::endl;
return true;
}
ss << "Error\nExpect:" << std::endl;
ss << expect << std::endl;
ss << "Found:" << std::endl;
ss << given << std::endl;
return false;
}
bool Tester::it(std::string des, const std::vector<double>& expect, const std::vector<double>& given, double esp)
{
ss << des << ": ";
if(expect.size()!=given.size())
{
ss << "Error: Size Unmatched\nExpected:" << endl;
ss << expect.size() << endl;
ss << "Found:" << endl;
ss << given.size();
}
for(int i=0;i<expect.size();i++)
{
double diff = abs(expect[i] - given[i]);
if (diff < esp)
{
continue;
}
ss << "Error\nExpected:" << std::endl;
for (int i = 0; i < expect.size(); i++)ss << expect[i] << ", ";
ss << endl;
ss << "Found:" << std::endl;
for (int i = 0; i < given.size(); i++)ss << given[i] << ", ";
ss << endl;
return false;
}
return true;
}
bool Tester::it(const std::string des, bool flag) const
{
ss << des << ": ";
ss << (flag ? "OK" : "Error") << std::endl;
return flag;
}