SourceXtractorPlusPlus  0.14
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestUtils.h
Go to the documentation of this file.
1 
24 #ifndef _COMPAREIMAGES_H
25 #define _COMPAREIMAGES_H
26 
27 #include "SEUtils/IsClose.h"
28 
29 namespace SourceXtractor {
30 
31 template <typename T, typename U>
32 boost::test_tools::predicate_result compareImages(
33  const T& ref, const U& val, double atol = 1e-8, double rtol = 1e-5) {
34  boost::test_tools::predicate_result res(true);
35 
36  for (int x = 0; x < ref->getWidth(); ++x) {
37  for (int y = 0; y < ref->getHeight(); ++y) {
38  auto expected = ref->getValue(x, y);
39  auto value = val->getValue(x, y);
40  if (!isClose(expected, value, atol, rtol)) {
41  res = false;
42  res.message() << "Not matching values at position " << x << "," << y
43  << ": " << expected << " != " << value << "\n";
44  }
45  }
46  }
47 
48  return res;
49 }
50 
51 template <typename T, typename U>
52 boost::test_tools::predicate_result compareCollections(
53  const T& ref, const U& val, double atol = 1e-8, double rtol = 1e-5) {
54  boost::test_tools::predicate_result res(true);
55 
56  auto ref_i = std::begin(ref);
57  auto val_i = std::begin(val);
58  int i = 0;
59 
60  while (ref_i != std::end(ref) && val_i != std::end(val)) {
61 
62  if (!isClose(*ref_i, *val_i, atol, rtol)) {
63  res = false;
64  res.message() << "Not matching values at position " << i << ": " << *ref_i << " != " << *val_i << "\n";
65  }
66 
67  ++ref_i;
68  ++val_i;
69  ++i;
70  }
71 
72  if (ref_i != std::end(ref) || val_i != std::end(val)) {
73  res = false;
74  res.message() << "The sequences have different length!" << "\n";
75  }
76 
77  return res;
78 }
79 
80 boost::test_tools::predicate_result checkIsClose(double ref, const double val, double atol = 1e-8, double rtol = 1e-5) {
81  boost::test_tools::predicate_result res(true);
82  if (!isClose(ref, val, atol, rtol)) {
83  res = false;
84  res.message() << "Values not close enough: " << ref << " " << val << " with absolute tolerance " << atol
85  << " and relative " << rtol << "\n";
86  }
87  return res;
88 }
89 
90 } // end SourceXtractor
91 
92 #endif // _COMPAREIMAGES_H
T atol(T...args)
boost::test_tools::predicate_result compareImages(const T &ref, const U &val, double atol=1e-8, double rtol=1e-5)
Definition: TestUtils.h:32
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
T end(T...args)
bool isClose(double a, double b, double atol=1e-8, double rtol=1e-5)
Definition: IsClose.h:28
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
boost::test_tools::predicate_result checkIsClose(double ref, const double val, double atol=1e-8, double rtol=1e-5)
Definition: TestUtils.h:80
T begin(T...args)
boost::test_tools::predicate_result compareCollections(const T &ref, const U &val, double atol=1e-8, double rtol=1e-5)
Definition: TestUtils.h:52