QA: numeric evaluator: add a context to tests

This allows a failing test to report which case failed more clearly.

Add a quick helper to make an "in -> out" context string.

(cherry picked from commit 3f32dc9a64)
This commit is contained in:
John Beard 2019-04-08 15:54:29 +01:00
parent 8b503a06fa
commit fd698653d9
2 changed files with 43 additions and 17 deletions

View File

@ -26,8 +26,7 @@
* Test suite for #NUMERIC_EVALUATOR
*/
#include <boost/test/test_case_template.hpp>
#include <boost/test/unit_test.hpp>
#include <unit_test_utils/unit_test_utils.h>
#include <libeval/numeric_evaluator.h>
@ -161,17 +160,20 @@ BOOST_AUTO_TEST_CASE( Results )
{
for( const auto& c : eval_cases_valid )
{
// Clear for new string input
m_eval.Clear();
BOOST_TEST_CONTEXT( KI_TEST::InOutString( c.input, c.exp_result ) )
{
// Clear for new string input
m_eval.Clear();
m_eval.Process( c.input );
m_eval.Process( c.input );
// These are all valid
BOOST_CHECK_EQUAL( m_eval.IsValid(), true );
BOOST_CHECK_EQUAL( m_eval.Result(), c.exp_result );
// These are all valid
BOOST_CHECK_EQUAL( m_eval.IsValid(), true );
BOOST_CHECK_EQUAL( m_eval.Result(), c.exp_result );
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
}
}
}
@ -214,16 +216,19 @@ BOOST_AUTO_TEST_CASE( ResultsInvalid )
{
for( const auto& c : eval_cases_invalid )
{
// Clear for new string input
m_eval.Clear();
BOOST_TEST_CONTEXT( c.input )
{
// Clear for new string input
m_eval.Clear();
m_eval.Process( c.input );
m_eval.Process( c.input );
// These are all valid
BOOST_CHECK_EQUAL( m_eval.IsValid(), false );
// These are all valid
BOOST_CHECK_EQUAL( m_eval.IsValid(), false );
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
}
}
}

View File

@ -230,6 +230,27 @@ void CheckUnorderedMatches(
}
}
/**
* Get a simple string "aIn -> aOut".
*
* Useful for BOOST_TEST_CONTEXT blocks as a brief description where a full
* case name would be a bit too much.
*
* @tparam IN the input type
* @tparam OUT the output type
* @param aIn the input
* @param aOut the output
* @return "aIn -> aOut"
*/
template<typename IN, typename OUT>
std::string InOutString( const IN& aIn, const OUT& aOut )
{
std::stringstream ss;
ss << aIn << " -> " << aOut;
return ss.str();
}
} // namespace KI_TEST
#endif // UNIT_TEST_UTILS__H