Skip to content

Commit

Permalink
Add [TEUCHOS_]TEST_COMPARE_CONST() macros (trilinos#2247)
Browse files Browse the repository at this point in the history
This was need for clear output for the test in NOX Thyra_Heq.C.

I just added a simple usage of this macro.  But we really need better unit
tests for all of thse macros.
  • Loading branch information
bartlettroscoe committed Feb 28, 2018
1 parent 6085ea2 commit 0862b7a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/teuchos/core/src/Teuchos_LocalTestingHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
TEUCHOS_TEST_COMPARE( v1, comp, v2, out, success )


/** \brief Assert that v1 comp v2 (where comp = '==', '>=", "!=", etc) where
* the second object v2 is printed as value.
*
* \ingroup Teuchos_UnitTestAssertMacros_grp
*/
#define TEST_COMPARE_CONST( v1, comp, v2 ) \
TEUCHOS_TEST_COMPARE_CONST( v1, comp, v2, out, success )


/** \brief Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
*
* Works for any object types that support a1[i], a1.size(), a2[j], and
Expand Down
19 changes: 19 additions & 0 deletions packages/teuchos/core/src/Teuchos_TestingHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@ bool compareFloatingArrays(
}


/** \brief Compare an object and a constant using an input comparsion
* operator.
*
* The test succeeds (passes) if and only if "(v1) comp (v2)".
* For example, TEUCHOS_TEST_COMPARE( 2, <, 3, out, success )
* succeeds, but TEUCHOS_TEST_COMPARE( 2, >, 3, out, success )
* and TEUCHOS_TEST_COMPARE( 3, <, 2, out, success ) both fail.
*
* \ingroup teuchos_testing_grp
*/
#define TEUCHOS_TEST_COMPARE_CONST( v1, comp, v2, out, success ) \
{ \
out << #v1" = "<<(v1)<<" "#comp" "<<(v2)<<" : "; \
const bool l_result = (v1) comp (v2); \
if (!l_result) (success) = false; \
(out) << TEUCHOS_PASS_FAIL(l_result) << "\n"; \
}


/** \brief Test that the chunk of code 'code' throws an expected exception.
*
* 'code' is a chunk of code to execute. It will be executed exactly
Expand Down
1 change: 1 addition & 0 deletions packages/teuchos/core/test/UnitTest/vector_UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( vector, sizedConstruct, T )
TEST_EQUALITY( as<int>(a.size()), n );
TEST_COMPARE( a.max_size(), >=, as<size_type>(n) );
TEST_COMPARE( as<int>(a.capacity()), >=, n );
TEST_COMPARE_CONST( as<int>(a.capacity()), >=, n );
}


Expand Down

0 comments on commit 0862b7a

Please sign in to comment.