aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-10-07 12:44:42 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-10-07 12:44:42 +0000
commitae2072406c725912da95ec0843209f4a8e35beb7 (patch)
tree99fb4ba493e663b4d42bd945a3dadfd5b156a491 /test
parentc768a44909ab52720a8f205dc78611bce83a55e6 (diff)
Introduce Numeric Traits, with fuzzy compares, random numbers, etc.
Diffstat (limited to 'test')
-rw-r--r--test/main.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/main.h b/test/main.h
index 1cdc781d7..06f295ece 100644
--- a/test/main.h
+++ b/test/main.h
@@ -47,4 +47,35 @@ class EigenTest : public QObject
void testMatrixManip();
};
+template<typename T> T TestEpsilon();
+template<> int TestEpsilon<int>() { return 0; }
+template<> float TestEpsilon<float>() { return 1e-2f; }
+template<> double TestEpsilon<double>() { return 1e-4; }
+template<typename T> T TestEpsilon<std::complex<T> >() { return TestEpsilon<T>(); }
+
+template<typename T> bool TestNegligible(const T& a, const T& b)
+{
+ return(EiAbs(a) <= EiAbs(b) * TestEpsilon<T>());
+}
+
+template<typename T> bool TestApprox(const T& a, const T& b)
+{
+ if(EiTraits<T>::IsFloat)
+ return(EiAbs(a - b) <= std::min(EiAbs(a), EiAbs(b)) * TestEpsilon<T>());
+ else
+ return(a == b);
+}
+
+template<typename T> bool TestLessThanOrApprox(const T& a, const T& b)
+{
+ if(EiTraits<T>::IsFloat)
+ return(a < b || EiApprox(a, b));
+ else
+ return(a <= b);
+}
+
+#define QVERIFY_NEGLIGIBLE(a, b) QVERIFY(TestNegligible(a, b))
+#define QVERIFY_APPROX(a, b) QVERIFY(TestApprox(a, b))
+#define QVERIFY_LESS_THAN_OR_APPROX(a, b) QVERIFY(TestLessThanOrApprox(a, b))
+
#endif // EI_TEST_MAIN_H