Update the apply_permutation tests to use the BOOST_CHECK_EQUAL_COLLECTIONS facilities. Based on https://github.com/boostorg/algorithm/pull/42 Thanks to Jeremy for the patch

This commit is contained in:
Marshall Clow
2019-07-03 07:44:25 -07:00
parent 9477cd8be0
commit 0a57ec30a2

View File

@ -14,19 +14,19 @@
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test.hpp>
namespace ba = boost::algorithm;
void test_apply_permutation()
BOOST_AUTO_TEST_CASE(test_apply_permutation)
{
//Empty
{
std::vector<int> vec, order, result;
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//1 element
{
@ -36,7 +36,7 @@ void test_apply_permutation()
result = vec;
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//2 elements, no changes
{
@ -46,7 +46,7 @@ void test_apply_permutation()
result = vec;
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//2 elements, changed
{
@ -56,7 +56,7 @@ void test_apply_permutation()
result.push_back(2); result.push_back(1);
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Multiple elements, no changes
{
@ -66,7 +66,7 @@ void test_apply_permutation()
result = vec;
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Multiple elements, changed
{
@ -76,7 +76,7 @@ void test_apply_permutation()
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Just test range interface
{
@ -86,18 +86,18 @@ void test_apply_permutation()
result = vec;
ba::apply_permutation(vec, order);
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
}
void test_apply_reverse_permutation()
BOOST_AUTO_TEST_CASE(test_apply_reverse_permutation)
{
//Empty
{
std::vector<int> vec, order, result;
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//1 element
{
@ -107,7 +107,7 @@ void test_apply_reverse_permutation()
result = vec;
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//2 elements, no changes
{
@ -117,7 +117,7 @@ void test_apply_reverse_permutation()
result = vec;
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//2 elements, changed
{
@ -127,7 +127,7 @@ void test_apply_reverse_permutation()
result.push_back(2); result.push_back(1);
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Multiple elements, no changes
{
@ -137,7 +137,7 @@ void test_apply_reverse_permutation()
result = vec;
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Multiple elements, changed
{
@ -147,7 +147,7 @@ void test_apply_reverse_permutation()
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
//Just test range interface
{
@ -157,12 +157,6 @@ void test_apply_reverse_permutation()
result = vec;
ba::apply_reverse_permutation(vec, order);
BOOST_CHECK(vec == result);
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
}
}
BOOST_AUTO_TEST_CASE(test_main)
{
test_apply_permutation();
test_apply_reverse_permutation();
}