Thyra Version of the Day
Thyra_TestingToolsDecl.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_TESTING_TOOLS_DECL_HPP
00043 #define THYRA_TESTING_TOOLS_DECL_HPP
00044 
00045 #include "Thyra_OperatorVectorTypes.hpp"
00046 #include "Teuchos_VerbosityLevel.hpp"
00047 #include "Teuchos_TestingHelpers.hpp"
00048 
00049 namespace Thyra {
00050 
00051 
00056 inline const std::string passfail(const bool result)
00057 {
00058   return Teuchos::passfail(result);
00059 }
00060 
00061 
00066 template <class Scalar>
00067 inline
00068 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
00069 relErr( const Scalar &s1, const Scalar &s2 )
00070 {
00071   return Teuchos::relErr<Scalar>(s1, s2);
00072 }
00073 
00074 
00081 template <class Scalar>
00082 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
00083 relVectorErr( const VectorBase<Scalar> &v1, const VectorBase<Scalar> &v2 );
00084 
00085 
00087 template<class Scalar>
00088 inline
00089 THYRA_DEPRECATED
00090 bool testRelErr(
00091   const std::string &v1_name,
00092   const Scalar &v1,
00093   const std::string &v2_name,
00094   const Scalar &v2,
00095   const std::string &maxRelErr_error_name,
00096   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_error,
00097   const std::string &maxRelErr_warning_name,
00098   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_warning,
00099   std::ostream *out,
00100   const std::string &leadingIndent = std::string("")
00101   )
00102 {
00103   // ToDo: Indent correctly!
00104   return Teuchos::testRelErr(v1_name, v1, v2_name, v2,
00105     maxRelErr_error_name, maxRelErr_error,
00106     maxRelErr_warning_name, maxRelErr_warning,
00107     Teuchos::ptr(out) );
00108 }
00109 
00110 
00121 template<class Scalar1, class Scalar2, class ScalarMag>
00122 bool testRelErrors(
00123   const std::string &v1_name,
00124   const ArrayView<const Scalar1> &v1,
00125   const std::string &v2_name,
00126   const ArrayView<const Scalar2> &v2,
00127   const std::string &maxRelErr_error_name,
00128   const ScalarMag &maxRelErr_error,
00129   const std::string &maxRelErr_warning_name,
00130   const ScalarMag &maxRelErr_warning,
00131   const Ptr<std::ostream> &out,
00132   const std::string &leadingIndent = std::string("")
00133   );
00134 
00135 
00137 template<class Scalar1, class Scalar2, class ScalarMag>
00138 THYRA_DEPRECATED
00139 bool testRelErrors(
00140   const int num_scalars,
00141   const std::string &v1_name,
00142   const Scalar1 v1[],
00143   const std::string &v2_name,
00144   const Scalar2 v2[],
00145   const std::string &maxRelErr_error_name,
00146   const ScalarMag &maxRelErr_error,
00147   const std::string &maxRelErr_warning_name,
00148   const ScalarMag &maxRelErr_warning,
00149   std::ostream *out,
00150   const std::string &leadingIndent = std::string("")
00151   )
00152 {
00153   using Teuchos::arrayView;
00154   return testRelErrors(
00155     v1_name, arrayView(v1, num_scalars),
00156     v2_name, arrayView(v2, num_scalars),
00157     maxRelErr_error_name, maxRelErr_error,
00158     maxRelErr_warning_name, maxRelErr_warning,
00159     Teuchos::ptr(out),
00160     leadingIndent
00161     );
00162 }
00163 
00164 
00175 template<class Scalar>
00176 bool testRelNormDiffErr(
00177   const std::string &v1_name,
00178   const VectorBase<Scalar> &v1,
00179   const std::string &v2_name,
00180   const VectorBase<Scalar> &v2,
00181   const std::string &maxRelErr_error_name,
00182   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_error,
00183   const std::string &maxRelErr_warning_name,
00184   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_warning,
00185   std::ostream *out,
00186   const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_LOW,
00187   const std::string &leadingIndent = std::string("")
00188   );
00189 
00190 
00197 template<class Scalar>
00198 bool testMaxErr(
00199   const std::string &error_name,
00200   const Scalar &error,
00201   const std::string &max_error_name,
00202   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
00203   const std::string &max_warning_name,
00204   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
00205   std::ostream *out,
00206   const std::string &leadingIndent = std::string("")
00207   );
00208 
00209 
00218 template<class Scalar>
00219 bool testMaxErrors(
00220   const std::string &error_name,
00221   const ArrayView<const typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &errors,
00222   const std::string &max_error_name,
00223   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
00224   const std::string &max_warning_name,
00225   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
00226   const Ptr<std::ostream> &out,
00227   const std::string &leadingIndent = std::string("")
00228   );
00229 
00230 
00232 template<class Scalar>
00233 THYRA_DEPRECATED
00234 bool testMaxErrors(
00235   const int num_scalars,
00236   const std::string &error_name,
00237   const Scalar error[],
00238   const std::string &max_error_name,
00239   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
00240   const std::string &max_warning_name,
00241   const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
00242   std::ostream *out,
00243   const std::string &leadingIndent = std::string("")
00244   )
00245 {
00246   return testMaxErrors<Scalar>(error_name,
00247     Teuchos::arrayView<const Scalar>(error, num_scalars),
00248     max_error_name, max_error, max_warning_name, max_warning,
00249     Teuchos::ptr(out), leadingIndent
00250     );
00251 }
00252 
00253 
00260 bool testBoolExpr(
00261   const std::string &boolExprName,
00262   const bool &boolExpr,
00263   const bool &boolExpected,
00264   const Ptr<std::ostream> &out,
00265   const std::string &leadingIndent = std::string("")
00266   );
00267 
00268 
00270 inline
00271 THYRA_DEPRECATED
00272 bool testBoolExpr(
00273   const std::string &boolExprName,
00274   const bool &boolExpr,
00275   const bool &boolExpected,
00276   std::ostream *out,
00277   const std::string &leadingIndent = std::string("")
00278   )
00279 {
00280   return testBoolExpr(boolExprName, boolExpr, boolExpected,
00281     Teuchos::ptr(out), leadingIndent);
00282 }
00283 
00284 
00309 void printTestResults(
00310   const bool result,
00311   const std::string &test_summary,
00312   const bool show_all_tests,
00313   bool *success,
00314   std::ostream *out
00315   );
00316 
00317 
00325 template<class Scalar>
00326 std::ostream& operator<<( std::ostream& o, const VectorBase<Scalar>& v );
00327 
00328 
00336 template<class Scalar>
00337 std::ostream& operator<<( std::ostream& o, const LinearOpBase<Scalar>& M );
00338 
00339 } // namespace Thyra
00340 
00341 
00342 // //////////////////////////
00343 // Inline functions                        
00344 
00345 
00346 inline
00347 void Thyra::printTestResults(
00348   const bool result,
00349   const std::string &test_summary,
00350   const bool show_all_tests,
00351   bool *success,
00352   std::ostream *out
00353   )
00354 {
00355   if (!result) *success = false;
00356   if (out) {
00357     if( !result || show_all_tests )
00358       *out << std::endl << test_summary;
00359     else
00360       *out << "passed!\n";
00361   }
00362 }
00363 
00364 
00365 #endif // THYRA_TESTING_TOOLS_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines