diff --git a/tvmet-1.7.1/testsuite/compare.h b/tvmet-1.7.1/testsuite/compare.h new file mode 100644 index 000000000..3e27af8af --- /dev/null +++ b/tvmet-1.7.1/testsuite/compare.h @@ -0,0 +1,94 @@ +/* This file is part of Eigen, a C++ template library for linear algebra + * Copyright (C) 2006-2007 Benoit Jacob + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: SelfTest.cc,v 1.1 2004/04/24 11:55:15 opetzold Exp $ + */ + +/* This file is mostly a duplication of util/Fuzzy.h, but with 1000 times + * bigger epsilon. This prevents false positives in tests. + */ + +#ifndef EIGEN_TESTSUITE_COMPARE_H +#define EIGEN_TESTSUITE_COMPARE_H + +#include + +#include +#include +#include + +#include + +template inline typename tvmet::Traits::real_type test_epsilon() +{ return static_cast::real_type>(0); } +template<> inline float test_epsilon() { return 1e-2f; } +template<> inline double test_epsilon() { return 1e-8; } +template<> inline float test_epsilon >() { return test_epsilon(); } +template<> inline double test_epsilon >() { return test_epsilon(); } + +/** + * Short version: returns true if the absolute value of \a a is much smaller + * than that of \a b. + * + * Full story: returns ( abs(a) <= abs(b) * test_epsilon ). + */ +template bool test_isNegligible( const T& a, const T& b ) +{ + return( tvmet::Traits::abs(a) + <= tvmet::Traits::abs(b) + * test_epsilon() ); +} + +/** + * Short version: returns true if \a a is approximately zero. + * + * Full story: returns test_isNegligible( a, static_cast(1) ); + */ +template bool test_isZero( const T& a ) +{ + return test_isNegligible( a, static_cast(1) ); +} + +/** + * Short version: returns true if a is very close to b, false otherwise. + * + * Full story: returns abs( a - b ) <= min( abs(a), abs(b) ) * test_epsilon. + */ +template bool test_isApprox( const T& a, const T& b ) +{ + return( tvmet::Traits::abs( a - b ) + <= std::min( tvmet::Traits::abs(a), + tvmet::Traits::abs(b) ) * test_epsilon() ); +} + +/** + * Short version: returns true if a is smaller or approximately equalt to b, false otherwise. + * + * Full story: returns a <= b || test_isApprox(a, b); + */ +template bool test_isLessThan( const T& a, const T& b ) +{ + return( tvmet::Traits::isLessThan_nonfuzzy(a, b) || test_isApprox(a, b) ); +} + +#define TEST(a) QVERIFY(a) +#define TEST_NEGLIGIBLE(a,b) QVERIFY(test_isNegligible(a,b)) +#define TEST_ZERO(a) QVERIFY(test_isZero(a)) +#define TEST_APPROX(a,b) QVERIFY(test_isApprox(a,b)) +#define TEST_LESSTHAN(a,b) QVERIFY(test_isLessThan(a,b)) + +#endif // EIGEN_TESTSUITE_COMPARE_H