Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/TestAssertions.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Erik Weitnauer ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00033 00034 #pragma once 00035 00036 #ifdef HAVE_GTEST 00037 00038 #include <gtest/gtest.h> 00039 #include <ICLUtils/Point32f.h> 00040 #include <ICLMath/FixedVector.h> 00041 #include <ICLMath/DynMatrixUtils.h> 00042 00043 namespace icl { 00044 namespace utils{ 00045 00052 template<class T, unsigned int WIDTH, unsigned int HEIGHT> 00053 testing::AssertionResult isNear(const FixedMatrix<T,WIDTH,HEIGHT> &matrix_a, 00054 const FixedMatrix<T,WIDTH,HEIGHT> &matrix_b, 00055 T delta) { 00056 for (unsigned int x=0; x<WIDTH; x++) for (unsigned int y=0; y<HEIGHT; y++) { 00057 if ((matrix_a(x,y)-matrix_b(x,y) > delta) || 00058 (matrix_b(x,y)-matrix_a(x,y) > delta)) { 00059 return testing::AssertionFailure() 00060 << "The difference of matrix A(" << x << ", " << y 00061 << ") and matrix B(" << x << ", " << y << ") is " << matrix_a(x,y)-matrix_b(x,y) 00062 << ", which exceeds delta, where\nA=\n" << matrix_a << "\nB=\n" << matrix_b 00063 << "\ndelta=" << delta << "."; 00064 } 00065 } 00066 return testing::AssertionSuccess(); 00067 } // namespace utils 00068 } 00069 00076 template<class T, unsigned int DIM> 00077 testing::AssertionResult isNear(const FixedColVector<T,DIM> &vector_a, 00078 const FixedColVector<T,DIM> &vector_b, 00079 T delta) { 00080 for (unsigned int i=0; i<DIM; i++) { 00081 if (abs(vector_a[i]-vector_b[i]) > delta) { 00082 return testing::AssertionFailure() 00083 << "The difference of col vector a[" << i << "] and col vector b[" 00084 << i << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n" 00085 << "a=" << vector_a.transp() << "\nb=" << vector_b.transp() 00086 << "\ndelta=" << delta << "."; 00087 00088 } 00089 } 00090 return testing::AssertionSuccess(); 00091 } 00092 00099 template<class T, unsigned int DIM> 00100 testing::AssertionResult isNear(const FixedRowVector<T,DIM> &vector_a, 00101 const FixedRowVector<T,DIM> &vector_b, 00102 T delta) { 00103 for (unsigned int i=0; i<DIM; i++) { 00104 if (abs(vector_a[i]-vector_b[i]) > delta) { 00105 return testing::AssertionFailure() 00106 << "The difference of row vector a[" << i << "] and row vector b[" << i 00107 << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n" 00108 << "a=" << vector_a << "\nb=" << vector_b 00109 << "\ndelta=" << delta << "."; 00110 00111 } 00112 } 00113 return testing::AssertionSuccess(); 00114 } 00115 00120 testing::AssertionResult isNear(const Point32f &p, 00121 const Point32f &q, 00122 float delta) { 00123 float dist = sqrt((p.x-q.x)*(p.x-q.x) + (p.y-q.y)*(p.y-q.y)); 00124 if (dist > delta) { 00125 return testing::AssertionFailure() 00126 << "The distance of points " << p << " and " << q << " is " 00127 << dist << ", which exceeds delta=" << delta << "."; 00128 } 00129 return testing::AssertionSuccess(); 00130 } 00131 } 00132 00133 #endif