Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TestingToolsDecl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_TESTING_TOOLS_DECL_HPP
11 #define THYRA_TESTING_TOOLS_DECL_HPP
12 
13 #include "Thyra_OperatorVectorTypes.hpp"
14 #include "Teuchos_VerbosityLevel.hpp"
15 #include "Teuchos_TestingHelpers.hpp"
16 
17 namespace Thyra {
18 
19 
24 inline const std::string passfail(const bool result)
25 {
26  return Teuchos::passfail(result);
27 }
28 
29 
34 template <class Scalar>
35 inline
37 relErr( const Scalar &s1, const Scalar &s2 )
38 {
39  return Teuchos::relErr<Scalar>(s1, s2);
40 }
41 
42 
49 template <class Scalar>
51 relVectorErr( const VectorBase<Scalar> &v1, const VectorBase<Scalar> &v2 );
52 
53 
64 template<class Scalar1, class Scalar2, class ScalarMag>
65 bool testRelErrors(
66  const std::string &v1_name,
67  const ArrayView<const Scalar1> &v1,
68  const std::string &v2_name,
69  const ArrayView<const Scalar2> &v2,
70  const std::string &maxRelErr_error_name,
71  const ScalarMag &maxRelErr_error,
72  const std::string &maxRelErr_warning_name,
73  const ScalarMag &maxRelErr_warning,
74  const Ptr<std::ostream> &out,
75  const std::string &leadingIndent = std::string("")
76  );
77 
78 
89 template<class Scalar>
91  const std::string &v1_name,
92  const VectorBase<Scalar> &v1,
93  const std::string &v2_name,
94  const VectorBase<Scalar> &v2,
95  const std::string &maxRelErr_error_name,
96  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_error,
97  const std::string &maxRelErr_warning_name,
98  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_warning,
99  std::ostream *out,
101  const std::string &leadingIndent = std::string("")
102  );
103 
104 
111 template<class Scalar>
112 bool testMaxErr(
113  const std::string &error_name,
114  const Scalar &error,
115  const std::string &max_error_name,
116  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
117  const std::string &max_warning_name,
118  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
119  std::ostream *out,
120  const std::string &leadingIndent = std::string("")
121  );
122 
123 
132 template<class Scalar>
133 bool testMaxErrors(
134  const std::string &error_name,
135  const ArrayView<const typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &errors,
136  const std::string &max_error_name,
137  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
138  const std::string &max_warning_name,
139  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
140  const Ptr<std::ostream> &out,
141  const std::string &leadingIndent = std::string("")
142  );
143 
144 
151 bool testBoolExpr(
152  const std::string &boolExprName,
153  const bool &boolExpr,
154  const bool &boolExpected,
155  const Ptr<std::ostream> &out,
156  const std::string &leadingIndent = std::string("")
157  );
158 
159 
184 void printTestResults(
185  const bool result,
186  const std::string &test_summary,
187  const bool show_all_tests,
188  const Ptr<bool> &success,
189  const Ptr<std::ostream> &out
190  );
191 
208 public:
210  TestResultsPrinter(const RCP<FancyOStream> &out, const bool show_all_tests);
220  void printTestResults(const bool this_result, const Ptr<bool> &success);
221 private:
222  RCP<FancyOStream> out_;
223  bool show_all_tests_;
224  std::ostringstream ossStore_;
225  RCP<FancyOStream> oss_;
226  bool printedTestResults_;
227  TestResultsPrinter(); // Not defined!
228  TestResultsPrinter(const TestResultsPrinter&); // Not defined!
229 };
230 
231 
239 template<class Scalar>
240 std::ostream& operator<<( std::ostream& o, const VectorBase<Scalar>& v );
241 
242 
250 template<class Scalar>
251 std::ostream& operator<<( std::ostream& o, const LinearOpBase<Scalar>& M );
252 
253 } // namespace Thyra
254 
255 
256 #endif // THYRA_TESTING_TOOLS_DECL_HPP
Control printing of test results.
bool testMaxErrors(const std::string &error_name, const ArrayView< const typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &errors, const std::string &max_error_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_error, const std::string &max_warning_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_warning, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Check that an array of errors is less than some error tolerence.
const std::string passfail(const bool result)
bool testRelNormDiffErr(const std::string &v1_name, const VectorBase< Scalar > &v1, const std::string &v2_name, const VectorBase< Scalar > &v2, const std::string &maxRelErr_error_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &maxRelErr_error, const std::string &maxRelErr_warning_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &maxRelErr_warning, std::ostream *out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_LOW, const std::string &leadingIndent=std::string(""))
Compute, check and optionally print the relative errors in two vectors.
bool testMaxErr(const std::string &error_name, const Scalar &error, const std::string &max_error_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_error, const std::string &max_warning_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_warning, std::ostream *out, const std::string &leadingIndent=std::string(""))
Check that an error is less than some error tolerence.
RCP< FancyOStream > replaceOStream(const RCP< FancyOStream > &out)
Replace the underlying output stream (used for unit testing this class).
void printTestResults(const bool this_result, const Ptr< bool > &success)
Print the test result.
~TestResultsPrinter()
Print the test results on destruction if not already printed.
Teuchos::ScalarTraits< Scalar >::magnitudeType relVectorErr(const VectorBase< Scalar > &v1, const VectorBase< Scalar > &v2)
Return relative error of two vectors.
Teuchos::ScalarTraits< typename std::common_type< Scalar1, Scalar2 >::type >::magnitudeType relErr(const Scalar1 &s1, const Scalar2 &s2)
RCP< FancyOStream > getTestOStream()
Return the stream used for testing.
bool testRelErrors(const std::string &v1_name, const ArrayView< const Scalar1 > &v1, const std::string &v2_name, const ArrayView< const Scalar2 > &v2, const std::string &maxRelErr_error_name, const ScalarMag &maxRelErr_error, const std::string &maxRelErr_warning_name, const ScalarMag &maxRelErr_warning, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Compute, check and optionally print the relative errors in two scalar arays.
bool testBoolExpr(const std::string &boolExprName, const bool &boolExpr, const bool &boolExpected, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Check a boolean result against expected result.