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.
This commit is contained in:
parent
0b33df8831
commit
3f32dc9a64
|
@ -26,8 +26,7 @@
|
||||||
* Test suite for #NUMERIC_EVALUATOR
|
* Test suite for #NUMERIC_EVALUATOR
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/test/test_case_template.hpp>
|
#include <unit_test_utils/unit_test_utils.h>
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
#include <libeval/numeric_evaluator.h>
|
#include <libeval/numeric_evaluator.h>
|
||||||
|
|
||||||
|
@ -160,6 +159,8 @@ static const std::vector<EVAL_CASE> eval_cases_valid = {
|
||||||
BOOST_AUTO_TEST_CASE( Results )
|
BOOST_AUTO_TEST_CASE( Results )
|
||||||
{
|
{
|
||||||
for( const auto& c : eval_cases_valid )
|
for( const auto& c : eval_cases_valid )
|
||||||
|
{
|
||||||
|
BOOST_TEST_CONTEXT( KI_TEST::InOutString( c.input, c.exp_result ) )
|
||||||
{
|
{
|
||||||
// Clear for new string input
|
// Clear for new string input
|
||||||
m_eval.Clear();
|
m_eval.Clear();
|
||||||
|
@ -173,6 +174,7 @@ BOOST_AUTO_TEST_CASE( Results )
|
||||||
// Does original text still match?
|
// Does original text still match?
|
||||||
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
|
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EVAL_INVALID_CASE
|
struct EVAL_INVALID_CASE
|
||||||
|
@ -213,6 +215,8 @@ static const std::vector<EVAL_INVALID_CASE> eval_cases_invalid = {
|
||||||
BOOST_AUTO_TEST_CASE( ResultsInvalid )
|
BOOST_AUTO_TEST_CASE( ResultsInvalid )
|
||||||
{
|
{
|
||||||
for( const auto& c : eval_cases_invalid )
|
for( const auto& c : eval_cases_invalid )
|
||||||
|
{
|
||||||
|
BOOST_TEST_CONTEXT( c.input )
|
||||||
{
|
{
|
||||||
// Clear for new string input
|
// Clear for new string input
|
||||||
m_eval.Clear();
|
m_eval.Clear();
|
||||||
|
@ -225,6 +229,7 @@ BOOST_AUTO_TEST_CASE( ResultsInvalid )
|
||||||
// Does original text still match?
|
// Does original text still match?
|
||||||
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
|
BOOST_CHECK_EQUAL( m_eval.OriginalText(), c.input );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
|
@ -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
|
} // namespace KI_TEST
|
||||||
|
|
||||||
#endif // UNIT_TEST_UTILS__H
|
#endif // UNIT_TEST_UTILS__H
|
Loading…
Reference in New Issue