00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef THYRA_TESTERBASE_HPP
00031 #define THYRA_TESTERBASE_HPP
00032
00033 #include "Thyra_LinearOperatorImpl.hpp"
00034 #include "Thyra_TestSpecifier.hpp"
00035 #include "Teuchos_ScalarTraits.hpp"
00036 #include "Teuchos_Comm.hpp"
00037 #include "Teuchos_CommHelpers.hpp"
00038
00039
00040 namespace Thyra {
00041
00043 template <class Scalar>
00044 class TesterBase
00045 {
00046 public:
00048 typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
00049
00051 TesterBase(const RCP<const Comm<int> >& comm,
00052 const VectorSpace<Scalar>& space, int nCols,
00053 Teuchos::RCP<Teuchos::FancyOStream>& out)
00054 : comm_(comm), space_(space), nCols_(nCols), out_(out)
00055 {
00056 using std::endl;
00057 *out << "==========================================================================="
00058 << endl;
00059 *out << " testing on type "
00060 << Teuchos::ScalarTraits<Scalar>::name() << endl;
00061 *out << "==========================================================================="
00062 << endl;
00063 }
00064
00066 virtual ~TesterBase(){;}
00067
00069 virtual bool runAllTests() const = 0 ;
00070
00071
00073 bool checkTest(const TestSpecifier<Scalar>& spec,
00074 const ScalarMag& err,
00075 const string& testName) const ;
00076
00078 void randomizeVec(Vector<Scalar>& x) const ;
00079
00081 LinearOperator<Scalar> randomDenseOp() const ;
00082
00084 const VectorSpace<Scalar>& space() const {return space_;}
00085
00087 ostream& out() const {return *out_;}
00088
00090 const Comm<int>& comm() const {return *comm_;}
00091
00092 private:
00093 RCP<const Comm<int> > comm_;
00094 VectorSpace<Scalar> space_;
00095 int nCols_;
00096 mutable Teuchos::RCP<Teuchos::FancyOStream> out_;
00097 };
00098
00099
00100 template <class Scalar>
00101 inline void TesterBase<Scalar>
00102 ::randomizeVec(Vector<Scalar>& x) const
00103 {
00104 typedef ScalarTraits<Scalar> ST;
00105 randomize(Scalar(-ST::one()),Scalar(+ST::one()),x.ptr().get());
00106
00107 }
00108
00109
00110 template <class Scalar>
00111 inline bool TesterBase<Scalar>
00112 ::checkTest(const TestSpecifier<Scalar>& spec,
00113 const ScalarMag& err,
00114 const string& testName) const
00115 {
00116
00117 using std::endl;
00118
00119 bool rtn = true;
00120 if (err > spec.errorTol())
00121 {
00122 *out_ << testName << " test FAILED: err=" << err << ", tol = "
00123 << spec.errorTol() << endl;
00124 rtn = false;
00125 }
00126 else if (err > spec.warningTol())
00127 {
00128 *out_ << "WARNING: " << testName << " test err="
00129 << err << " could not beat tol = "
00130 << spec.warningTol() << endl;
00131 }
00132 else
00133 {
00134 *out_ << "test " << testName << " PASSED with tol=" << spec.errorTol() << endl;
00135 }
00136 return rtn;
00137 }
00138
00139
00140 template <class Scalar>
00141 inline LinearOperator<Scalar> TesterBase<Scalar>
00142 ::randomDenseOp() const
00143 {
00144 typedef ScalarTraits<Scalar> ST;
00145 RCP<MultiVectorBase<Scalar> > mv = space_.createMembers(nCols_);
00146 randomize(-ST::one(), ST::one(), &*mv);
00147 RCP<LinearOpBase<Scalar> > rtn = mv;
00148 return rtn;
00149 }
00150
00151
00152 }
00153
00154
00155 #endif // THYRA_TESTERBASE_HPP