qa: Add StrNumCmp test

This commit is contained in:
Seth Hillbrand 2019-03-01 07:22:35 -08:00
parent 40309a17ef
commit 16b3c80a7c
1 changed files with 50 additions and 1 deletions

View File

@ -58,4 +58,53 @@ BOOST_AUTO_TEST_CASE( TrailingInt )
}
}
BOOST_AUTO_TEST_SUITE_END()
/**
* Test the #StrNumCmp method.
*/
BOOST_AUTO_TEST_CASE( NaturalNumberCompare )
{
using CASE = std::pair<std::pair<std::string, std::string>, std::pair<int, int>>;
const std::vector<CASE> cases = {
{ { "a", "b" }, { -1, -1 } },
{ { "b", "a" }, { 1, 1 } },
{ { "a", "a" }, { 0, 0 } },
{ { "a", "A" }, { 1, 0 } },
{ { "A", "a" }, { -1, 0 } },
{ { "a", "" }, { 1, 1 } },
{ { "", "a" }, { -1, -1 } },
{ { "1", "" }, { 1, 1 } },
{ { "", "1" }, { -1, -1 } },
{ { "10", "2" }, { 1, 1 } },
{ { "2", "10" }, { -1, -1 } },
{ { "2", "2" }, { 0, 0 } },
{ { "10", "10" }, { 0, 0 } },
{ { "01", "1" }, { 0, 0 } },
{ { "01a", "1a" }, { 0, 0 } },
{ { "01a", "1b" }, { -1, -1 } },
{ { "01b", "1a" }, { 1, 1 } },
{ { "10 ten", "2 two" }, { 1, 1 } },
{ { "SYM1", "sym2" }, { -1, -1 } },
{ { "sym2", "SYM1" }, { 1, 1 } },
{ { "a10b20c30", "a10b20c31" }, { -1, -1 } },
{ { "a10b20c31", "a10b20c30" }, { 1, 1 } },
{ { "10UF", "10UF" }, { 0, 0 } },
{ { "10uF", "10uF" }, { 0, 0 } },
{ { "u10", "u10" }, { 0, 0 } },
{ { "U10", "U10" }, { 0, 0 } },
{ { "u10", "U10" }, { 1, 0 } },
{ { "U10", "u10" }, { -1, 0 } }
};
for( const auto& c : cases )
{
BOOST_CHECK_MESSAGE( StrNumCmp( c.first.first, c.first.second ) == c.second.first,
c.first.first + " AND " + c.first.second + " failed for case sensitive" );
BOOST_CHECK_MESSAGE(
StrNumCmp( c.first.first, c.first.second, INT_MAX, true ) == c.second.second,
c.first.first + " AND " + c.first.second + " failed for case insensitive" );
}
}
BOOST_AUTO_TEST_SUITE_END()