75 explicit RunTests(
const double tolerance = 1E-4);
82 virtual void run_tests() = 0;
85 bool is_everything_ok()
const;
89 int main_return_value()
const;
92 void set_tolerance(
const double tolerance);
95 double get_tolerance()
const;
102 bool check(
const bool,
const std::string& str =
"");
109 bool check_if_equal(
const std::string& a,
const std::string& b,
const std::string& str =
"");
110 bool check_if_equal(
const double a,
const double b,
const std::string& str =
"");
112 bool check_if_equal(
const short a,
const short b,
const std::string& str =
"");
113 bool check_if_equal(
const unsigned short a,
const unsigned short b,
const std::string& str =
"");
114 bool check_if_equal(
const int a,
const int b,
const std::string& str =
"");
115 bool check_if_equal(
const unsigned int a,
const unsigned int b,
const std::string& str =
"");
116 bool check_if_equal(
const long a,
const long b,
const std::string& str =
"");
117 bool check_if_equal(
const unsigned long a,
const unsigned long b,
const std::string& str =
"");
118 #ifdef BOOST_HAS_LONG_LONG 120 bool check_if_equal(
const long long a,
const long long b,
const std::string& str =
"");
121 bool check_if_equal(
const unsigned long long a,
const unsigned long long b,
const std::string& str =
"");
123 bool check_if_equal(
const Bin& a,
const Bin& b,
const std::string& str =
"")
125 return this->check_if_equal_generic(a, b, str);
130 return this->check_if_equal_generic(a, b, str);
136 bool check_if_equal(
const std::complex<T> a,
const std::complex<T> b,
const std::string& str =
"")
138 return check_if_equal(a.real(), b.real(), str) && check_if_equal(a.imag(), b.imag(), str);
146 std::cerr <<
"Error: unequal ranges. " << str << std::endl;
147 return everything_ok =
false;
152 if (!check_if_equal(t1[i], t2[i], str))
154 std::cerr <<
"(at VectorWithOffset<" <<
typeid(T).name() <<
"> first mismatch at index " << i <<
")\n";
155 return everything_ok =
false;
163 bool check_if_equal(
const std::vector<T>& t1,
const std::vector<T>& t2,
const std::string& str =
"")
165 if (t1.size() != t2.size())
167 std::cerr <<
"Error: unequal ranges. " << str << std::endl;
168 return everything_ok =
false;
171 bool all_equal =
true;
172 for (
unsigned int i = 0; i < t1.size(); i++)
174 if (!check_if_equal(t1[i], t2[i], str))
176 std::cerr <<
"(at vector<" <<
typeid(T).name() <<
"> mismatch at index " << i <<
")\n";
191 std::cerr <<
"Error: unequal ranges. " << str << std::endl;
192 return everything_ok =
false;
198 template <
int num_dimensions,
class coordT>
201 const std::string& str =
"")
203 if (
norm(a - b) > tolerance)
205 std::cerr <<
"Error : Unequal Coordinate value are " << a <<
" and " << b <<
". " << str << std::endl;
206 everything_ok =
false;
219 bool check_if_zero(
const double a,
const std::string& str =
"");
220 bool check_if_zero(
const short a,
const std::string& str =
"");
221 bool check_if_zero(
const unsigned short a,
const std::string& str =
"");
222 bool check_if_zero(
const int a,
const std::string& str =
"");
223 bool check_if_zero(
const unsigned int a,
const std::string& str =
"");
224 bool check_if_zero(
const long a,
const std::string& str =
"");
225 bool check_if_zero(
const unsigned long a,
const std::string& str =
"");
226 #ifdef BOOST_HAS_LONG_LONG 227 bool check_if_zero(
const long long a,
const std::string& str =
"");
228 bool check_if_zero(
const unsigned long long a,
const std::string& str =
"");
238 if (!check_if_zero(t[i], str))
240 std::cerr <<
"(at VectorWithOffset<" <<
typeid(T).name() <<
"> first mismatch at index " << i <<
")\n";
248 template <
int num_dimensions,
class coordT>
251 if (
norm(a) > tolerance)
253 std::cerr <<
"Error : Coordinate value is " << a <<
" expected 0s. " << str << std::endl;
254 everything_ok =
false;
263 template <
class T1,
class T2>
264 inline bool check_if_less(T1 a, T2 b,
const std::string& str =
"");
278 std::cerr <<
"Error : unequal values are " << a <<
" and " << b <<
". " << str << std::endl;
279 everything_ok =
false;
290 if ((a != static_cast<T>(0)))
292 std::cerr <<
"Error : 0 value is " << a <<
" ." << str << std::endl;
293 everything_ok =
false;
305 RunTests::RunTests(
const double tolerance)
306 : tolerance(tolerance),
312 #if defined(_DEBUG) && defined(__MSL__) 313 DebugNewReportLeaks();
317 std::cerr <<
"\nAll tests ok !\n\n" << std::endl;
319 std::cerr <<
"\nEnd of tests. Please correct errors !\n\n" << std::endl;
351 std::cerr <<
"Error. " << str << std::endl;
358 RunTests::check_if_equal(
const std::string& a,
const std::string& b,
const std::string& str)
378 RunTests::check_if_equal(
const double a,
const double b,
const std::string& str)
380 const double diff = fabs(b - a);
384 const double largest = (std::max(fabs(b), fabs(a)));
388 std::cerr <<
"Error : unequal values are " << a <<
" and " << b <<
". " << str << std::endl;
397 RunTests::check_if_equal(
const short a,
const short b,
const std::string& str)
402 RunTests::check_if_equal(
const unsigned short a,
const unsigned short b,
const std::string& str)
407 RunTests::check_if_equal(
const int a,
const int b,
const std::string& str)
412 RunTests::check_if_equal(
const unsigned int a,
const unsigned int b,
const std::string& str)
417 RunTests::check_if_equal(
const long a,
const long b,
const std::string& str)
422 RunTests::check_if_equal(
const unsigned long a,
const unsigned long b,
const std::string& str)
426 #ifdef BOOST_HAS_LONG_LONG 428 RunTests::check_if_equal(
const long long a,
const long long b,
const std::string& str)
433 RunTests::check_if_equal(
const unsigned long long a,
const unsigned long long b,
const std::string& str)
444 std::cerr <<
"Error: unequal proj_data_info. " << str << std::endl;
448 for (
auto i1 = t1.
begin(), i2 = t2.
begin(); i1 != t1.
end(); ++i1, ++i2)
450 if (!check_if_equal(*i1, *i2, str))
488 #ifdef BOOST_HAS_LONG_LONG 507 std::cerr <<
"Error : 0 value is " << a <<
" ." << str << std::endl;
515 template <
class T1,
class T2>
521 std::cerr <<
"Error : " << a <<
" is larger than " << b <<
", " << str << std::endl;
A class which reads/writes projection data from/to memory.
Definition: ProjDataInMemory.h:38
A class for storing coordinates of a detection.
Definition: DetectionPosition.h:58
iterator begin()
start value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:209
virtual ~RunTests()
Destructor, outputs a diagnostic message.
Definition: RunTests.h:310
A templated class for vectors, but with indices starting not from 0.
Definition: ArrayFilter1DUsingConvolution.h:31
int get_min_index() const
get value of first valid index
Definition: VectorWithOffset.inl:116
This class defines ranges which can be 'irregular'.
Definition: ArrayFunctionObject.h:32
double get_tolerance() const
Get value used in floating point comparisons (see check_* functions)
Definition: RunTests.h:341
Declaration of class stir::ProjDataInMemory.
bool is_everything_ok() const
Returns if all checks were fine upto now.
Definition: RunTests.h:323
bool check_if_zero(const VectorWithOffset< T > &t, const std::string &str="")
use check_if_zero on all elements
Definition: RunTests.h:234
bool check_if_zero(const double a, const std::string &str="")
Definition: RunTests.h:503
Input/output of basic vector-like types to/from streams.
shared_ptr< const ProjDataInfo > get_proj_data_info_sptr() const
Get shared pointer to proj data info.
Definition: ProjData.inl:52
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
bool check_if_zero(const BasicCoordinate< num_dimensions, coordT > &a, const std::string &str="")
compare norm with tolerance
Definition: RunTests.h:249
bool check_if_equal_generic(const T &a, const T &b, const std::string &str)
function that is called by some check_if_equal implementations. It just uses operator!= ...
Definition: RunTests.h:274
bool check_if_equal(const VectorWithOffset< T > &t1, const VectorWithOffset< T > &t2, const std::string &str="")
check equality by comparing ranges and calling check_if_equal on all elements
Definition: RunTests.h:142
Declaration of class stir::DetectionPosition.
A class for storing coordinates and value of a single projection bin.
Definition: Bin.h:48
Declaration of class stir::Bin.
bool check(const bool, const std::string &str="")
Tests if true, str can be used to tell what you are testing.
Definition: RunTests.h:347
void set_tolerance(const double tolerance)
Set value used in floating point comparisons (see check_* functions)
Definition: RunTests.h:335
defines the stir::VectorWithOffset class
bool check_if_equal(const std::vector< T > &t1, const std::vector< T > &t2, const std::string &str="")
check equality by comparing size and calling check_if_equal on all elements
Definition: RunTests.h:163
A base class for making test classesWith a derived class, an application could look like...
Definition: RunTests.h:71
iterator end()
end value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:219
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition: BasicCoordinate.inl:426
This file defines the stir::IndexRange class.
double tolerance
tolerance for comparisons with real values
Definition: RunTests.h:268
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition: BasicCoordinate.h:53
bool check_if_equal(const std::complex< T > a, const std::complex< T > b, const std::string &str="")
check equality by calling check_if_equal on real and imaginary parts
Definition: RunTests.h:136
int get_max_index() const
get value of last valid index
Definition: VectorWithOffset.inl:123
bool check_if_equal(const BasicCoordinate< num_dimensions, coordT > &a, const BasicCoordinate< num_dimensions, coordT > &b, const std::string &str="")
check equality by comparing norm(a-b) with tolerance
Definition: RunTests.h:199
bool check_if_less(T1 a, T2 b, const std::string &str="")
check if a<b
Definition: RunTests.h:517
bool everything_ok
variable storing current status
Definition: RunTests.h:270
bool check_if_zero_generic(T a, const std::string &str)
function that is called by some check_if_zero implementations. It just uses operator!= ...
Definition: RunTests.h:288
int main_return_value() const
Handy return value for a main() function.
Definition: RunTests.h:329