CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cuv_test.hpp
1 //*LB*
2 // Copyright (c) 2010, University of Bonn, Institute for Computer Science VI
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the University of Bonn
14 // nor the names of its contributors may be used to endorse or promote
15 // products derived from this software without specific prior written
16 // permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //*LE*
29 
30 
31 
32 
33 
34 #ifndef __CUV_TEST_HPP__
35 #define __CUV_TEST_HPP__
36 #include <boost/test/included/unit_test.hpp>
37 #include <boost/test/floating_point_comparison.hpp>
38 
39 #define MAT_CMP(X,Y,PREC) \
40  if(1){ \
41  bool (*matrix_eq_cmp)(const __typeof__(X)&, const __typeof__(Y)&, float) = make_matrix_eq(X,Y); \
42  BOOST_CHECK_PREDICATE(matrix_eq_cmp,(X)(Y)(PREC)); \
43  }
44 
45  template<class M, class N>
46  bool matrix_eq(const M& w, const N& w2, float prec)
47  {
48  boost::test_tools::percent_tolerance_t <float> pt(prec);
49  boost::test_tools::close_at_tolerance<typename M::value_type> cmp(pt);
50  for(int i=0;i<w.shape()[0];i++){
51  for(int j=0;j<w.shape()[1];j++){
52  if( !cmp(w(i,j), w2(i,j)))
53  return false;
54  }
55  }
56  return true;
57  }
58 
59  template<class M, class N>
60  bool (*make_matrix_eq(const M&,const N&))(const M& w, const N& w2, float){
61  return &matrix_eq<M,N>;
62  }
63 
64 #endif
65