1 #ifndef TMV_TEST_H
2 #define TMV_TEST_H
3
4 #ifndef XTEST
5 #define XTEST 0
6 #endif
7
8 #include <iostream>
9 #include <cmath>
10 #include "tmv/TMV_Base.h"
11
12 #ifndef NO_TEST_DOUBLE
13 #define TEST_DOUBLE
14 #endif
15
16 #ifndef NO_TEST_FLOAT
17 #define TEST_FLOAT
18 #endif
19
20 #ifndef NO_TEST_COMPLEX
21 #define TEST_COMPLEX
22 #endif
23
24 #define EPS (10*tmv::TMV_Epsilon<T>())
25
26 extern bool showtests;
27 extern bool showacc;
28 extern bool showdiv;
29 extern bool donorm2;
30 extern bool showstartdone;
31 extern bool aliasok;
32 extern bool symoprod;
33 extern bool dontthrow;
34 extern std::string lastsuccess;
35
36 #ifdef TMV_DEBUG
PreAssert(const std::string & s)37 inline void PreAssert(const std::string& s)
38 {
39 if (showtests) {
40 std::cout<<"Trying: "<<s;
41 std::cout.flush();
42 }
43 }
44 #else
PreAssert(const std::string &)45 inline void PreAssert(const std::string& ) {}
46 #endif
47
DoAssert(bool x,std::string s)48 inline void DoAssert(bool x, std::string s)
49 {
50 if (x) {
51 #ifdef TMV_DEBUG
52 if (showtests) std::cout<<" Passed"<<std::endl;
53 lastsuccess = s;
54 #endif
55 } else {
56 #ifdef TMV_DEBUG
57 if (showtests) std::cout<<" Failed"<<std::endl;
58 if (dontthrow) std::cout<<"Failed test: "<<s<<std::endl;
59 else {
60 #endif
61 #ifdef NOTHROW
62 std::cerr<<"Error in test: "<<s<<std::endl; exit(1);
63 #else
64 throw tmv::Error("Error in test: "+s);
65 #endif
66 #ifdef TMV_DEBUG
67 }
68 #endif
69 }
70 }
71
72 #define Assert(x,s) \
73 do { \
74 PreAssert(s); \
75 DoAssert(x,s); \
76 } while (false)
77
78 template <class M1, class M2, class T>
Equal(const M1 & a,const M2 & b,T eps)79 inline bool Equal(const M1& a, const M2& b, T eps)
80 {
81 T normdiff = Norm(a-b);
82 if (showtests) std::cout<<" "<<normdiff<<" <=? "<<eps<<" ";
83 return normdiff <= eps;
84 }
85 template <class X1, class X2, class T>
Equal2(const X1 & a,const X2 & b,T eps)86 inline bool Equal2(const X1& a, const X2& b, T eps)
87 {
88 T absdiff = tmv::TMV_ABS2(a-b);
89 if (showtests) std::cout<<" "<<absdiff<<" <=? "<<eps<<" ";
90 return absdiff <= eps;
91 }
92
93 template <class M1, class M2>
Equal(const M1 & a,const M2 & b,int)94 inline bool Equal(const M1& a, const M2& b, int )
95 { return a == b; }
96 template <class X1, class X2>
Equal2(const X1 & a,const X2 & b,int)97 inline bool Equal2(const X1& a, const X2& b, int )
98 { return a == b; }
99
100 // C++ I/O doesn't seem capable of reading in at higher accuracy than double precision.
101 // If you do fin >> x; where x is a long double variable and the text in the file is
102 // 1.234, say, then (x-1.234) will not be zero after this. Instead it will be something
103 // of order 1.e-17. So we only check the IO at double precision for long doubles.
104 template <class M1, class M2, class T>
EqualIO(const M1 & a,const M2 & b,T eps)105 inline bool EqualIO(const M1& a, const M2& b, T eps)
106 { return Equal(a,b,eps); }
107 template <class M1, class M2>
EqualIO(const M1 & a,const M2 & b,long double eps)108 inline bool EqualIO(const M1& a, const M2& b, long double eps )
109 { return Equal(a,b,10*tmv::TMV_Epsilon<double>()); }
110
111
112 extern bool XXDEBUG1;
113 extern bool XXDEBUG2;
114 extern bool XXDEBUG3;
115 extern bool XXDEBUG4;
116 extern bool XXDEBUG5;
117 extern bool XXDEBUG6;
118 extern bool XXDEBUG7;
119 extern bool XXDEBUG8;
120 extern bool XXDEBUG9;
121
122 #endif
123