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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_TESTING_TOOLS_DECL_HPP
43 #define THYRA_TESTING_TOOLS_DECL_HPP
44 
45 #include "Thyra_OperatorVectorTypes.hpp"
46 #include "Teuchos_VerbosityLevel.hpp"
47 #include "Teuchos_TestingHelpers.hpp"
48 
49 namespace Thyra {
50 
51 
56 inline const std::string passfail(const bool result)
57 {
58  return Teuchos::passfail(result);
59 }
60 
61 
66 template <class Scalar>
67 inline
69 relErr( const Scalar &s1, const Scalar &s2 )
70 {
71  return Teuchos::relErr<Scalar>(s1, s2);
72 }
73 
74 
81 template <class Scalar>
83 relVectorErr( const VectorBase<Scalar> &v1, const VectorBase<Scalar> &v2 );
84 
85 
96 template<class Scalar1, class Scalar2, class ScalarMag>
97 bool testRelErrors(
98  const std::string &v1_name,
99  const ArrayView<const Scalar1> &v1,
100  const std::string &v2_name,
101  const ArrayView<const Scalar2> &v2,
102  const std::string &maxRelErr_error_name,
103  const ScalarMag &maxRelErr_error,
104  const std::string &maxRelErr_warning_name,
105  const ScalarMag &maxRelErr_warning,
106  const Ptr<std::ostream> &out,
107  const std::string &leadingIndent = std::string("")
108  );
109 
110 
121 template<class Scalar>
122 bool testRelNormDiffErr(
123  const std::string &v1_name,
124  const VectorBase<Scalar> &v1,
125  const std::string &v2_name,
126  const VectorBase<Scalar> &v2,
127  const std::string &maxRelErr_error_name,
128  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_error,
129  const std::string &maxRelErr_warning_name,
130  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &maxRelErr_warning,
131  std::ostream *out,
133  const std::string &leadingIndent = std::string("")
134  );
135 
136 
143 template<class Scalar>
144 bool testMaxErr(
145  const std::string &error_name,
146  const Scalar &error,
147  const std::string &max_error_name,
148  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
149  const std::string &max_warning_name,
150  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
151  std::ostream *out,
152  const std::string &leadingIndent = std::string("")
153  );
154 
155 
164 template<class Scalar>
165 bool testMaxErrors(
166  const std::string &error_name,
167  const ArrayView<const typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &errors,
168  const std::string &max_error_name,
169  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_error,
170  const std::string &max_warning_name,
171  const typename Teuchos::ScalarTraits<Scalar>::magnitudeType &max_warning,
172  const Ptr<std::ostream> &out,
173  const std::string &leadingIndent = std::string("")
174  );
175 
176 
183 bool testBoolExpr(
184  const std::string &boolExprName,
185  const bool &boolExpr,
186  const bool &boolExpected,
187  const Ptr<std::ostream> &out,
188  const std::string &leadingIndent = std::string("")
189  );
190 
191 
216 void printTestResults(
217  const bool result,
218  const std::string &test_summary,
219  const bool show_all_tests,
220  const Ptr<bool> &success,
221  const Ptr<std::ostream> &out
222  );
223 
225 THYRA_DEPRECATED void printTestResults(
226  const bool result,
227  const std::string &test_summary,
228  const bool show_all_tests,
229  bool *success,
230  std::ostream *out
231  );
232 
249 public:
251  TestResultsPrinter(const RCP<FancyOStream> &out, const bool show_all_tests);
261  void printTestResults(const bool this_result, const Ptr<bool> &success);
262 private:
263  RCP<FancyOStream> out_;
264  bool show_all_tests_;
265  std::ostringstream ossStore_;
266  RCP<FancyOStream> oss_;
267  bool printedTestResults_;
268  TestResultsPrinter(); // Not defined!
269  TestResultsPrinter(const TestResultsPrinter&); // Not defined!
270 };
271 
272 
280 template<class Scalar>
281 std::ostream& operator<<( std::ostream& o, const VectorBase<Scalar>& v );
282 
283 
291 template<class Scalar>
292 std::ostream& operator<<( std::ostream& o, const LinearOpBase<Scalar>& M );
293 
294 } // namespace Thyra
295 
296 
297 #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).
ScalarTraits< Scalar >::magnitudeType relErr(const Scalar &s1, const Scalar &s2)
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.
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.