12 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
const std::string& a_v,
const std::string& a_expected) {
14 a_out <<
"failed in file :" << std::endl
15 << a_file << std::endl
16 <<
"at line :" << std::endl
17 << a_line << std::endl
18 <<
"strg value \"" << a_v <<
"\"" << std::endl
19 <<
", expected \"" << a_expected <<
"\"." << std::endl;
25 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
bool a_v,
bool a_expected) {
27 a_out <<
"failed in file :" << std::endl
28 << a_file << std::endl
29 <<
"at line :" << std::endl
30 << a_line << std::endl
31 <<
"value " << (a_v?
"true":
"false") <<
", expected " << (a_expected?
"true":
"false") << std::endl;
37 #define TOOLS_TEST_FUNC(a__func) \
38 if(!tools::equal(a_out,__FILE__,__LINE__,(a__func),true)) return false;
40 template <
class CLASS>
41 inline bool valid_pointer(std::ostream& a_out,
const char* a_file,
int a_line,CLASS* a_p) {
43 a_out <<
"failed in file :" << std::endl
44 << a_file << std::endl
45 <<
"at line :" << std::endl
46 << a_line << std::endl
47 <<
"null pointer." << std::endl;
53 template <
class INTEGER>
54 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
const INTEGER& a_v,
const INTEGER& a_expected) {
56 a_out <<
"failed in file :" << std::endl
57 << a_file << std::endl
58 <<
"at line :" << std::endl
59 << a_line << std::endl
60 <<
"value " << a_v <<
", expected " << a_expected << std::endl;
66 template <
class INTEGER>
67 inline bool not_equal(std::ostream& a_out,
const char* a_file,
int a_line,
const INTEGER& a_v,
const INTEGER& a_expected) {
69 a_out <<
"failed in file :" << std::endl
70 << a_file << std::endl
71 <<
"at line :" << std::endl
72 << a_line << std::endl
73 <<
"value " << a_v <<
", expected " << a_expected << std::endl;
79 template <
class INTEGER>
80 inline bool ge(std::ostream& a_out,
const char* a_file,
int a_line,
const INTEGER& a_v,
const INTEGER& a_expected) {
82 a_out <<
"failed in file :" << std::endl
83 << a_file << std::endl
84 <<
"at line :" << std::endl
85 << a_line << std::endl
86 <<
"value " << a_v <<
" < " << a_expected << std::endl;
93 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
const REAL& a_v,
const REAL& a_expected,
const REAL& a_tolerance,REAL(*a_fabs)(
const REAL&)) {
94 REAL
diff = a_fabs(a_v-a_expected);
95 if(
diff>=a_tolerance) {
96 a_out <<
"failed in file :" << std::endl
97 << a_file << std::endl
98 <<
"at line :" << std::endl
99 << a_line << std::endl
100 <<
"value " << a_v <<
", expected " << a_expected <<
",diff " <<
diff << std::endl;
106 template <
class REAL>
107 inline bool not_equal(std::ostream& a_out,
const char* a_file,
int a_line,
const REAL& a_v,
const REAL& a_expected,
const REAL& a_tolerance,REAL(*a_fabs)(
const REAL&)) {
108 REAL
diff = a_fabs(a_v-a_expected);
109 if(
diff<a_tolerance) {
110 a_out <<
"failed in file :" << std::endl
111 << a_file << std::endl
112 <<
"at line :" << std::endl
113 << a_line << std::endl
114 <<
"value " << a_v <<
", not expected to be " << a_expected <<
",diff " <<
diff << std::endl;
121 template <
class NUMBER,
class PREC>
122 inline bool _equal(std::ostream& a_out,
const char* a_file,
int a_line,
const NUMBER& a_v,
const NUMBER& a_expected,
const PREC& a_tolerance,PREC(*a_fabs)(
const NUMBER&)) {
123 PREC
diff = a_fabs(a_v-a_expected);
124 if(
diff>=a_tolerance) {
125 a_out <<
"failed in file :" << std::endl
126 << a_file << std::endl
127 <<
"at line :" << std::endl
128 << a_line << std::endl
129 <<
"value " << a_v <<
", expected " << a_expected <<
",diff " <<
diff << std::endl;
135 template <
class REAL>
136 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
size_t a_size,
const REAL* a_v,
const REAL* a_expected,
const REAL& a_tolerance,REAL(*a_fabs)(
const REAL&)){
137 for(
size_t index=0;index<a_size;index++) {
138 if(!equal<REAL>(a_out,a_file,a_line,a_v[index],a_expected[index],a_tolerance,a_fabs))
return false;
143 template <
class VEC,
class REAL>
144 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
const VEC& a_1,
const VEC& a_2,
const REAL& a_tolerance,REAL(*a_fabs)(
const REAL&)){
145 if(a_1.dimension()!=a_2.dimension()) {
146 a_out <<
"failed in file :" << std::endl
147 << a_file << std::endl
148 <<
"at line :" << std::endl
149 << a_line << std::endl
150 <<
"vector dimension " << a_1.dimension() <<
" != " << a_2.dimension() << std::endl;
153 for(
size_t index=0;index<a_1.dimension();index++) {
154 if(!equal<REAL>(a_out,a_file,a_line,a_1[index],a_2[index],a_tolerance,a_fabs))
return false;
159 template <
class MAT,
class REAL>
160 inline bool mat_equal(std::ostream& a_out,
const char* a_file,
int a_line,
const MAT& a_1,
const MAT& a_2,
const REAL& a_tolerance,REAL(*a_fabs)(
const REAL&)){
161 if(a_1.dimension()!=a_2.dimension()) {
162 a_out <<
"failed in file :" << std::endl
163 << a_file << std::endl
164 <<
"at line :" << std::endl
165 << a_line << std::endl
166 <<
"matrix dimension " << a_1.dimension() <<
" != " << a_2.dimension() << std::endl;
169 if(a_1.data_size()!=a_2.data_size()) {
170 a_out <<
"failed in file :" << std::endl
171 << a_file << std::endl
172 <<
"at line :" << std::endl
173 << a_line << std::endl
174 <<
"matrix data_size " << a_1.data_size() <<
" != " << a_2.data_size() << std::endl;
177 for(
size_t index=0;index<a_1.data_size();index++) {
178 if(!equal<REAL>(a_out,a_file,a_line,a_1.data()[index],a_2.data()[index],a_tolerance,a_fabs))
return false;
189 inline bool equal(std::ostream& a_out,
const char* a_file,
int a_line,
const std::vector<std::string>& a_v,
const std::vector<std::string>& a_expected) {
190 if(a_v.size()!=a_expected.size()) {
191 a_out <<
"failed in file :" << std::endl
192 << a_file << std::endl
193 <<
"at line :" << std::endl
194 << a_line << std::endl
195 <<
"vector value.size() " << a_v.size() <<
", expected " << a_expected.size() << std::endl;
198 std::vector<std::string>::const_iterator it1 = a_v.begin();
199 std::vector<std::string>::const_iterator it2 = a_expected.begin();
200 for(;it1!=a_v.end();++it1,++it2) {
202 a_out <<
"failed in file :" << std::endl
203 << a_file << std::endl
204 <<
"at line :" << std::endl
205 << a_line << std::endl
206 <<
"line value \"" << (*it1) <<
"\"" << std::endl
207 <<
", expected \"" << (*it2) <<
"\"" << std::endl;