Bug fixes and is_partititioned_XXX for the 1.65.0 release

This commit is contained in:
Marshall Clow
2017-06-14 18:49:39 -07:00
28 changed files with 416 additions and 97 deletions

View File

@ -70,6 +70,9 @@ alias unit_test_framework
# Is_palindrome tests
[ run is_palindrome_test.cpp unit_test_framework : : : : is_palindrome_test ]
# Is_partitioned_until tests
[ run is_partitioned_until_test.cpp unit_test_framework : : : : is_partitioned_until_test ]
;
}

View File

@ -18,7 +18,7 @@
#include <list>
template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }

View File

@ -18,7 +18,7 @@
#include <list>
template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }

View File

@ -38,9 +38,6 @@ struct functorComparator
}
};
#define Begin(arr) (arr)
#define End(arr) (arr+(sizeof(arr)/(sizeof(arr[0]))))
void test_is_palindrome()
{
const std::list<int> empty;
@ -54,14 +51,14 @@ void test_is_palindrome()
// Test a default operator==
BOOST_CHECK ( ba::is_palindrome(empty));
BOOST_CHECK ( ba::is_palindrome(singleElement));
BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome)));
BOOST_CHECK ( ba::is_palindrome(Begin(oddPalindrome), End(oddPalindrome)));
BOOST_CHECK ( ba::is_palindrome(Begin(evenPalindrome), End(evenPalindrome)));
BOOST_CHECK (!ba::is_palindrome(Begin(evenNonPalindrome), End(evenNonPalindrome)));
BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome)));
BOOST_CHECK ( ba::is_palindrome(boost::begin(oddPalindrome), boost::end(oddPalindrome)));
BOOST_CHECK ( ba::is_palindrome(boost::begin(evenPalindrome), boost::end(evenPalindrome)));
BOOST_CHECK (!ba::is_palindrome(boost::begin(evenNonPalindrome), boost::end(evenNonPalindrome)));
//Test the custom comparators
BOOST_CHECK ( ba::is_palindrome(empty.begin(), empty.end(), functorComparator()));
BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome), funcComparator<int>));
BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome), funcComparator<int>));
BOOST_CHECK ( ba::is_palindrome(evenPalindrome, std::equal_to<int>()));
//Test C-strings like cases

View File

@ -0,0 +1,63 @@
/*
Copyright (c) Marshall Clow 2011-2012, Alexander Zaitsev <zamazan4ik@gmail.com>, 2017.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <boost/config.hpp>
#include <boost/algorithm/is_partitioned_until.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include <list>
namespace ba = boost::algorithm;
// namespace ba = boost;
template <typename T>
struct less_than {
public:
less_than ( T foo ) : val ( foo ) {}
less_than ( const less_than &rhs ) : val ( rhs.val ) {}
bool operator () ( const T &v ) const { return v < val; }
private:
less_than ();
less_than operator = ( const less_than &rhs );
T val;
};
void test_sequence1 () {
std::vector<int> v;
v.clear ();
for ( int i = 5; i < 15; ++i )
v.push_back ( i );
BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(3)) == v.end()); // no elements
BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(6)) == v.end()); // only the first element
BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(10)) == v.end()); // in the middle somewhere
BOOST_CHECK ( ba::is_partitioned_until ( v, less_than<int>(99)) == v.end()); // all elements satisfy
// With bidirectional iterators.
std::list<int> l;
for ( int i = 5; i < 15; ++i )
l.push_back ( i );
BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(3)) == l.end()); // no elements
BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(6)) == l.end()); // only the first element
BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(10)) == l.end()); // in the middle somewhere
BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than<int>(99)) == l.end()); // all elements satisfy
}
BOOST_AUTO_TEST_CASE( test_main )
{
test_sequence1 ();
}

View File

@ -18,7 +18,7 @@
#include <list>
template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }

View File

@ -18,7 +18,7 @@
#include <list>
template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }

View File

@ -7,6 +7,20 @@
#include <vector>
#include <iostream>
#if __cplusplus >= 201103L
#include <random>
std::default_random_engine gen;
template<typename RandomIt>
void do_shuffle(RandomIt first, RandomIt last)
{ std::shuffle(first, last, gen); }
#else
template<typename RandomIt>
void do_shuffle(RandomIt first, RandomIt last)
{ std::random_shuffle(first, last); }
#endif
namespace ba = boost::algorithm;
template <typename Iter>
@ -72,14 +86,14 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[5], 5);
// Mix them up and try again - single element
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b + 7, b + 8);
check_sequence (b, v.end(), b + 7, b + 8);
// BOOST_CHECK_EQUAL(v[7], 7);
// Mix them up and try again - at the end
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b + 7, v.end());
check_sequence (b, v.end(), b + 7, v.end());
@ -88,7 +102,7 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[9], 9);
// Mix them up and try again - at the beginning
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, b + 2);
check_sequence (b, v.end(), b, b + 2);
@ -96,12 +110,12 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[1], 1);
// Mix them up and try again - empty subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, b);
check_sequence (b, v.end(), b, b);
// Mix them up and try again - entire subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, v.end());
check_sequence (b, v.end(), b, v.end());
}
@ -120,14 +134,14 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[5], 4);
// Mix them up and try again - single element
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b + 7, b + 8, std::greater<int>());
check_sequence (b, v.end(), b + 7, b + 8, std::greater<int>());
// BOOST_CHECK_EQUAL(v[7], 2);
// Mix them up and try again - at the end
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b + 7, v.end(), std::greater<int>());
check_sequence (b, v.end(), b + 7, v.end(), std::greater<int>());
@ -136,7 +150,7 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[9], 0);
// Mix them up and try again - at the beginning
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, b + 2, std::greater<int>());
check_sequence (b, v.end(), b, b + 2, std::greater<int>());
@ -144,12 +158,12 @@ BOOST_AUTO_TEST_CASE( test_main )
// BOOST_CHECK_EQUAL(v[1], 8);
// Mix them up and try again - empty subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, b, std::greater<int>());
check_sequence (b, v.end(), b, b, std::greater<int>());
// Mix them up and try again - entire subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::partition_subrange(b, v.end(), b, v.end(), std::greater<int>());
check_sequence (b, v.end(), b, v.end(), std::greater<int>());
}

View File

@ -7,6 +7,20 @@
#include <vector>
#include <iostream>
#if __cplusplus >= 201103L
#include <random>
std::default_random_engine gen;
template<typename RandomIt>
void do_shuffle(RandomIt first, RandomIt last)
{ std::shuffle(first, last, gen); }
#else
template<typename RandomIt>
void do_shuffle(RandomIt first, RandomIt last)
{ std::random_shuffle(first, last); }
#endif
namespace ba = boost::algorithm;
template <typename Iter>
@ -53,14 +67,14 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[5], 5);
// Mix them up and try again - single element
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, b + 8);
check_sequence (b, v.end(), b + 7, b + 8);
BOOST_CHECK_EQUAL(v[7], 7);
// Mix them up and try again - at the end
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, v.end());
check_sequence (b, v.end(), b + 7, v.end());
@ -69,7 +83,7 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[9], 9);
// Mix them up and try again - at the beginning
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b + 2);
check_sequence (b, v.end(), b, b + 2);
@ -77,12 +91,12 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[1], 1);
// Mix them up and try again - empty subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b);
check_sequence (b, v.end(), b, b);
// Mix them up and try again - entire subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, v.end());
check_sequence (b, v.end(), b, v.end());
}
@ -101,14 +115,14 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[5], 4);
// Mix them up and try again - single element
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, b + 8, std::greater<int>());
check_sequence (b, v.end(), b + 7, b + 8, std::greater<int>());
BOOST_CHECK_EQUAL(v[7], 2);
// Mix them up and try again - at the end
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b + 7, v.end(), std::greater<int>());
check_sequence (b, v.end(), b + 7, v.end(), std::greater<int>());
@ -117,7 +131,7 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[9], 0);
// Mix them up and try again - at the beginning
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b + 2, std::greater<int>());
check_sequence (b, v.end(), b, b + 2, std::greater<int>());
@ -125,12 +139,12 @@ BOOST_AUTO_TEST_CASE( test_main )
BOOST_CHECK_EQUAL(v[1], 8);
// Mix them up and try again - empty subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, b, std::greater<int>());
check_sequence (b, v.end(), b, b, std::greater<int>());
// Mix them up and try again - entire subrange
std::random_shuffle(v.begin(), v.end());
do_shuffle(v.begin(), v.end());
ba::sort_subrange(b, v.end(), b, v.end(), std::greater<int>());
check_sequence (b, v.end(), b, v.end(), std::greater<int>());
}