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>
@ -160,6 +159,8 @@ static const std::vector<EVAL_CASE> eval_cases_valid = {
BOOST_AUTO_TEST_CASE( Results )
{
for( const auto& c : eval_cases_valid )
{
BOOST_TEST_CONTEXT( KI_TEST::InOutString( c.input, c.exp_result ) )
{
// Clear for new string input
m_eval.Clear();
@ -173,6 +174,7 @@ BOOST_AUTO_TEST_CASE( Results )
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
}
}
}
struct EVAL_INVALID_CASE
@ -213,6 +215,8 @@ static const std::vector<EVAL_INVALID_CASE> eval_cases_invalid = {
BOOST_AUTO_TEST_CASE( ResultsInvalid )
{
for( const auto& c : eval_cases_invalid )
{
BOOST_TEST_CONTEXT( c.input )
{
// Clear for new string input
m_eval.Clear();
@ -225,6 +229,7 @@ BOOST_AUTO_TEST_CASE( ResultsInvalid )
// Does original text still match?
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
}
}
}
BOOST_AUTO_TEST_SUITE_END()

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