1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_06E5D36EB6C211DEA317E19C55D89593
7 #define UUID_06E5D36EB6C211DEA317E19C55D89593
9 #include <boost/test/floating_point_comparison.hpp>
10 #include <boost/detail/lightweight_test.hpp>
13 #define BOOST_QVM_TEST_EQ(expra,exprb) ( ::test_qvm::detail::test_eq_impl(#expra, #exprb, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb) )
14 #define BOOST_QVM_TEST_NEQ(expra,exprb) ( ::test_qvm::detail::test_neq_impl(#expra, #exprb, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb) )
15 #define BOOST_QVM_TEST_CLOSE(expra,exprb,exprt) ( ::test_qvm::detail::test_close_impl(#expra, #exprb, #exprt, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb, exprt) )
17 #define BOOST_QVM_TEST_EQ_QUAT(expra,exprb) ( ::test_qvm::detail::test_eq_q_impl(#expra, #exprb, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb) )
18 #define BOOST_QVM_TEST_NEQ_QUAT(expra,exprb) ( ::test_qvm::detail::test_neq_q_impl(#expra, #exprb, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb) )
19 #define BOOST_QVM_TEST_CLOSE_QUAT(expra,exprb,exprt) ( ::test_qvm::detail::test_close_q_impl(#expra, #exprb, #exprt, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expra, exprb, exprt) )
29 close_at_tolerance( float a, float b, float tolerance )
31 return boost::math::fpc::close_at_tolerance<float>(tolerance,boost::math::fpc::FPC_STRONG)(a,b);
36 close_at_tolerance( double a, double b, double tolerance )
38 return boost::math::fpc::close_at_tolerance<double>(tolerance,boost::math::fpc::FPC_STRONG)(a,b);
41 template <class A,class B>
45 std::cerr << a << '\t' << b << std::endl;
48 template <class A,class B,int D>
50 dump_ab( A (&a)[D], B (&b)[D] )
52 for( int i=0; i!=D; ++i )
56 template <class A,class B>
58 test_eq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A a, B b )
60 using namespace ::boost::qvm;
63 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_EQ(" << expra << ',' << exprb
64 << ") failed in function " << function << '\n';
66 ++::boost::detail::test_errors();
70 template <class A,class B,int M,int N>
72 test_eq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[M][N], B (&b)[M][N] )
74 using namespace ::boost::qvm;
75 for( int i=0; i<M; ++i )
76 for( int j=0; j<N; ++j )
77 if( !(a[i][j]==b[i][j]) )
79 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_EQ(" << expra << ',' << exprb
80 << ") failed in function " << function << '\n';
82 ++::boost::detail::test_errors();
87 template <class A,class B,int D>
89 test_eq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[D], B (&b)[D] )
91 using namespace ::boost::qvm;
92 for( int i=0; i<D; ++i )
95 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_EQ" << expra << ',' << exprb
96 << ") failed in function " << function <<'\n';
98 ++::boost::detail::test_errors();
103 template <class A,class B>
105 test_eq_q_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[4], B (&b)[4] )
107 using namespace ::boost::qvm;
117 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_EQ" << expra << ',' << exprb
118 << ") failed in function " << function <<'\n';
120 ++::boost::detail::test_errors();
125 template <class A,class B>
127 test_neq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A a, B b )
129 using namespace ::boost::qvm;
132 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_NEQ(" << expra << ',' << exprb
133 << ") failed in function " << function << '\n';
135 ++::boost::detail::test_errors();
139 template <class A,class B,int M,int N>
141 test_neq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[M][N], B (&b)[M][N] )
143 using namespace ::boost::qvm;
144 for( int i=0; i<M; ++i )
145 for( int j=0; j<N; ++j )
146 if( a[i][j]!=b[i][j] )
148 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_NEQ(" << expra << ',' << exprb
149 << ") failed in function " << function << '\n';
151 ++::boost::detail::test_errors();
154 template <class A,class B,int D>
156 test_neq_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[D], B (&b)[D] )
158 using namespace ::boost::qvm;
159 for( int i=0; i<D; ++i )
162 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_NEQ(" << expra << ',' << exprb
163 << ") failed in function " << function << '\n';
165 ++::boost::detail::test_errors();
168 template <class A,class B>
170 test_neq_q_impl( char const * expra, char const * exprb, char const * file, int line, char const * function, A (&a)[4], B (&b)[4] )
172 using namespace ::boost::qvm;
182 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_EQ" << expra << ',' << exprb
183 << ") failed in function " << function <<'\n';
185 ++::boost::detail::test_errors();
190 template <class A,class B,class T>
192 test_close_impl( char const * expra, char const * /*exprb*/, char const * /*exprt*/, char const * file, int line, char const * function, A a, B b, T t )
194 if( !close_at_tolerance(a,b,t) )
196 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_CLOSE(" << expra << ',' << b << ',' << t
197 << ") failed in function " << function << '\n';
198 ++::boost::detail::test_errors();
203 template <class A,class B,class T,int M,int N>
205 test_close_impl( char const * expra, char const * exprb, char const * exprt, char const * file, int line, char const * function, A (&a)[M][N], B (&b)[M][N], T t )
207 for( int i=0; i<M; ++i )
208 for( int j=0; j<N; ++j )
209 if( !close_at_tolerance(a[i][j],b[i][j],t) )
211 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_CLOSE(" << expra << ',' << exprb << ',' << exprt
212 << ") failed in function " << function << '\n';
214 ++::boost::detail::test_errors();
219 template <class A,class B,class T,int D>
221 test_close_impl( char const * expra, char const * exprb, char const * exprt, char const * file, int line, char const * function, A (&a)[D], B (&b)[D], T t )
223 for( int i=0; i<D; ++i )
224 if( !close_at_tolerance(a[i],b[i],t) )
226 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_CLOSE(" << expra << ',' << exprb << ',' << exprt
227 << ") failed in function " << function << '\n';
229 ++::boost::detail::test_errors();
234 template <class A,class B,class T>
236 test_close_q_impl( char const * expra, char const * exprb, char const * exprt, char const * file, int line, char const * function, A (&a)[4], B (&b)[4], T t )
240 if( !close_at_tolerance(a[i],b[i],t) )
245 if( !close_at_tolerance(a[i],-b[i],t) )
247 std::cerr << file << "(" << line << "): BOOST_QVM_TEST_CLOSE_QUAT(" << expra << ',' << exprb << ',' << exprt
248 << ") failed in function " << function << '\n';
250 ++::boost::detail::test_errors();