Image Component Library (ICL)
TestAssertions.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/TestAssertions.h **
10 ** Module : ICLUtils **
11 ** Authors: Erik Weitnauer **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
33 
34 #pragma once
35 
36 #ifdef ICL_HAVE_GTEST
37 
38 #include <ICLUtils/CompatMacros.h>
39 #include <ICLUtils/Point32f.h>
40 #include <ICLMath/FixedVector.h>
41 #include <ICLMath/DynMatrixUtils.h>
42 #include <gtest/gtest.h>
43 
44 namespace icl {
45  namespace utils{
46 
53  template<class T, unsigned int WIDTH, unsigned int HEIGHT>
54  testing::AssertionResult isNear(const FixedMatrix<T,WIDTH,HEIGHT> &matrix_a,
55  const FixedMatrix<T,WIDTH,HEIGHT> &matrix_b,
56  T delta) {
57  for (unsigned int x=0; x<WIDTH; x++) for (unsigned int y=0; y<HEIGHT; y++) {
58  if ((matrix_a(x,y)-matrix_b(x,y) > delta) ||
59  (matrix_b(x,y)-matrix_a(x,y) > delta)) {
60  return testing::AssertionFailure()
61  << "The difference of matrix A(" << x << ", " << y
62  << ") and matrix B(" << x << ", " << y << ") is " << matrix_a(x,y)-matrix_b(x,y)
63  << ", which exceeds delta, where\nA=\n" << matrix_a << "\nB=\n" << matrix_b
64  << "\ndelta=" << delta << ".";
65  }
66  }
67  return testing::AssertionSuccess();
68  } // namespace utils
69 }
70 
77 template<class T, unsigned int DIM>
78 testing::AssertionResult isNear(const FixedColVector<T,DIM> &vector_a,
79  const FixedColVector<T,DIM> &vector_b,
80  T delta) {
81  for (unsigned int i=0; i<DIM; i++) {
82  if (abs(vector_a[i]-vector_b[i]) > delta) {
83  return testing::AssertionFailure()
84  << "The difference of col vector a[" << i << "] and col vector b["
85  << i << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n"
86  << "a=" << vector_a.transp() << "\nb=" << vector_b.transp()
87  << "\ndelta=" << delta << ".";
88 
89  }
90  }
91  return testing::AssertionSuccess();
92 }
93 
100 template<class T, unsigned int DIM>
101 testing::AssertionResult isNear(const FixedRowVector<T,DIM> &vector_a,
102  const FixedRowVector<T,DIM> &vector_b,
103  T delta) {
104  for (unsigned int i=0; i<DIM; i++) {
105  if (abs(vector_a[i]-vector_b[i]) > delta) {
106  return testing::AssertionFailure()
107  << "The difference of row vector a[" << i << "] and row vector b[" << i
108  << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n"
109  << "a=" << vector_a << "\nb=" << vector_b
110  << "\ndelta=" << delta << ".";
111 
112  }
113  }
114  return testing::AssertionSuccess();
115 }
116 
121 testing::AssertionResult isNear(const Point32f &p,
122  const Point32f &q,
123  float delta) {
124  float dist = sqrt((p.x-q.x)*(p.x-q.x) + (p.y-q.y)*(p.y-q.y));
125  if (dist > delta) {
126  return testing::AssertionFailure()
127  << "The distance of points " << p << " and " << q << " is "
128  << dist << ", which exceeds delta=" << delta << ".";
129  }
130  return testing::AssertionSuccess();
131 }
132 }
133 
134 #endif
ICLQt_API ImgQ sqrt(const ImgQ &image)
calls sqrt( each pixel)
undocument this line if you encounter any issues!
Definition: Any.h:37
ICLQt_API ImgQ abs(const ImgQ &image)
calls abs ( each pixel)