Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TestAssertions.h
Go to the documentation of this file.
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.LGPL **
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 ICL_HAVE_GTEST
00037 
00038 #include <ICLUtils/CompatMacros.h>
00039 #include <ICLUtils/Point32f.h>
00040 #include <ICLMath/FixedVector.h>
00041 #include <ICLMath/DynMatrixUtils.h>
00042 #include <gtest/gtest.h>
00043 
00044 namespace icl {
00045   namespace utils{
00046   
00053   template<class T, unsigned int WIDTH, unsigned int HEIGHT>
00054   testing::AssertionResult isNear(const FixedMatrix<T,WIDTH,HEIGHT> &matrix_a,
00055                                   const FixedMatrix<T,WIDTH,HEIGHT> &matrix_b,
00056                                   T delta) {
00057     for (unsigned int x=0; x<WIDTH; x++) for (unsigned int y=0; y<HEIGHT; y++) {
00058       if ((matrix_a(x,y)-matrix_b(x,y) > delta) ||
00059           (matrix_b(x,y)-matrix_a(x,y) > delta)) {
00060         return testing::AssertionFailure()
00061           << "The difference of matrix A(" << x << ", " << y
00062           << ") and matrix B(" << x << ", " << y << ") is " << matrix_a(x,y)-matrix_b(x,y)
00063           << ", which exceeds delta, where\nA=\n" << matrix_a << "\nB=\n" << matrix_b
00064           << "\ndelta=" << delta << ".";
00065       }
00066     }
00067     return testing::AssertionSuccess();
00068   } // namespace utils
00069 }
00070 
00077 template<class T, unsigned int DIM>
00078 testing::AssertionResult isNear(const FixedColVector<T,DIM> &vector_a,
00079                                 const FixedColVector<T,DIM> &vector_b,
00080                                 T delta) {
00081   for (unsigned int i=0; i<DIM; i++) {
00082     if (abs(vector_a[i]-vector_b[i]) > delta) {
00083       return testing::AssertionFailure()
00084         << "The difference of col vector a[" << i << "] and col vector b["
00085         << i << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n"
00086         << "a=" << vector_a.transp() << "\nb=" << vector_b.transp()
00087         << "\ndelta=" << delta << ".";
00088         
00089     }
00090   } 
00091   return testing::AssertionSuccess();
00092 }
00093 
00100 template<class T, unsigned int DIM>
00101 testing::AssertionResult isNear(const FixedRowVector<T,DIM> &vector_a,
00102                                 const FixedRowVector<T,DIM> &vector_b,
00103                                 T delta) {
00104   for (unsigned int i=0; i<DIM; i++) {
00105     if (abs(vector_a[i]-vector_b[i]) > delta) {
00106       return testing::AssertionFailure()
00107         << "The difference of row vector a[" << i << "] and row vector b[" << i
00108         << "] is " << vector_a[i]-vector_b[i] << ", which exceeds delta, where\n"
00109         << "a=" << vector_a << "\nb=" << vector_b
00110         << "\ndelta=" << delta << ".";
00111         
00112     }
00113   } 
00114   return testing::AssertionSuccess();
00115 }
00116 
00121 testing::AssertionResult isNear(const Point32f &p,
00122                                 const Point32f &q,
00123                                 float delta) {
00124   float dist = sqrt((p.x-q.x)*(p.x-q.x) + (p.y-q.y)*(p.y-q.y));
00125   if (dist > delta) {
00126     return testing::AssertionFailure()
00127       << "The distance of points " << p << " and " << q << " is "
00128       << dist << ", which exceeds delta=" << delta << ".";        
00129   }
00130   return testing::AssertionSuccess();
00131 }
00132 }
00133 
00134 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines