1 
2 // Copyright (c) 2007, 2008 libmv authors.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 // IN THE SOFTWARE.
21 
22 // This file is part of OpenMVG, an Open Multiple View Geometry C++ library.
23 
24 // Copyright (c) 2012, 2013 Pierre MOULON.
25 
26 // This Source Code Form is subject to the terms of the Mozilla Public
27 // License, v. 2.0. If a copy of the MPL was not distributed with this
28 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
29 
30 
31 #ifndef TESTING_TESTING_H_
32 #define TESTING_TESTING_H_
33 
34 #include "openMVG/numeric/eigen_alias_definition.hpp"
35 #include "openMVG/numeric/numeric.h"
36 #include "third_party/CppUnitLite/TestHarness.h"
37 
38 #define EXPECT_MATRIX_NEAR(a, b, tolerance) \
39 do { \
40   bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
41   CHECK_EQUAL(a.rows(),b.rows()); \
42   CHECK_EQUAL(a.cols(),b.cols()); \
43   if (dims_match) { \
44     for (int r = 0; r < a.rows(); ++r) { \
45       for (int c = 0; c < a.cols(); ++c) { \
46         DOUBLES_EQUAL(a(r, c), b(r, c), tolerance); \
47       } \
48     } \
49   } \
50 } while(false);
51 
52 #define EXPECT_MATRIX_NEAR_ZERO(a, tolerance) \
53 do { \
54   for (int r = 0; r < a.rows(); ++r) { \
55     for (int c = 0; c < a.cols(); ++c) { \
56       DOUBLES_EQUAL(0.0, a(r, c), tolerance) \
57     } \
58   } \
59 } while(false);
60 
61 #define EXPECT_MATRIX_EQ(a, b) \
62 do { \
63   bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
64   CHECK_EQUAL(a.rows(),b.rows()); \
65   CHECK_EQUAL(a.cols(),b.cols()); \
66   if (dims_match) { \
67     for (int r = 0; r < a.rows(); ++r) { \
68       for (int c = 0; c < a.cols(); ++c) { \
69         CHECK_EQUAL(a(r, c), b(r, c)) \
70       } \
71     } \
72   } \
73 } while(false);
74 
75 #define EXPECT_NEAR(expected,actual,threshold) \
76   DOUBLES_EQUAL(expected,actual,threshold);
77 
78 #define EXPECT_TRUE(condition) \
79   CHECK(condition);
80 
81 #define EXPECT_FALSE(condition) \
82   CHECK(!condition);
83 
84 #define EXPECT_EQ(a, b) CHECK_EQUAL(a,b);
85 
86 // Check that sin(angle(a, b)) < tolerance.
87 #define EXPECT_MATRIX_PROP(a, b, tolerance) \
88 do { \
89   bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
90   CHECK_EQUAL(a.rows(), b.rows()); \
91   CHECK_EQUAL(a.cols(), b.cols()); \
92   if (dims_match) { \
93     double c = CosinusBetweenMatrices(a, b); \
94     if (c * c < 1) { \
95       double s = sqrt(1 - c * c); \
96       DOUBLES_EQUAL(0.0, s, tolerance); \
97     } \
98   } \
99 } while(false);
100 
101 #endif  // TESTING_TESTING_H_
102