mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-30 20:47:15 +02:00
Fixed tests
[SVN r46599]
This commit is contained in:
@ -3,13 +3,13 @@
|
|||||||
// Boost Software License, Version 1.0. (See accompanying file
|
// Boost Software License, Version 1.0. (See accompanying file
|
||||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/algorithm/copy.hpp>
|
#include <boost/algorithm/copy.hpp>
|
||||||
#include <boost/test/included/test_exec_monitor.hpp>
|
#include <boost/test/included/test_exec_monitor.hpp>
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
// #include <boost/algorithm/all.hpp>
|
// #include <boost/algorithm/all.hpp>
|
||||||
// #include <boost/algorithm/select.hpp>
|
// #include <boost/algorithm/select.hpp>
|
||||||
|
|
||||||
@ -20,6 +20,8 @@ template <int v> bool IsLess ( int v2 ) { return v2 < v; }
|
|||||||
bool IsEven ( int v2 ) { return ( v2 & 1 ) == 0; }
|
bool IsEven ( int v2 ) { return ( v2 & 1 ) == 0; }
|
||||||
bool IsOdd ( int v2 ) { return ( v2 & 1 ) != 0; }
|
bool IsOdd ( int v2 ) { return ( v2 & 1 ) != 0; }
|
||||||
|
|
||||||
|
namespace bas = boost::algorithm::sequence;
|
||||||
|
|
||||||
void test_copy_if ()
|
void test_copy_if ()
|
||||||
{
|
{
|
||||||
const int vals [] = { 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1 };
|
const int vals [] = { 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1 };
|
||||||
@ -33,36 +35,36 @@ void test_copy_if ()
|
|||||||
|
|
||||||
// Copy_if from constant iterators
|
// Copy_if from constant iterators
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> );
|
bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
||||||
BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsNotEqual<0> ) == res.end ());
|
BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsNotEqual<0> ) == res.end ());
|
||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> );
|
bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( valsSize, res.size ());
|
BOOST_CHECK_EQUAL ( valsSize, res.size ());
|
||||||
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
// Copy_if using ranges
|
// Copy_if using ranges
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( cont, std::back_inserter(res), IsNotEqual<0> );
|
bas::copy_if ( cont, std::back_inserter(res), IsNotEqual<0> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
||||||
BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsEqual<0> ) == res.end ());
|
BOOST_CHECK ( std::find_if ( res.begin (), res.end (), IsEqual<0> ) == res.end ());
|
||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( cont, std::back_inserter(res), IsNotEqual<2> );
|
bas::copy_if ( cont, std::back_inserter(res), IsNotEqual<2> );
|
||||||
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
||||||
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if ( cont, std::back_inserter(res), IsEqual<2> );
|
bas::copy_if ( cont, std::back_inserter(res), IsEqual<2> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
// ---- Backwards tests ----
|
// ---- Backwards tests ----
|
||||||
@ -75,7 +77,7 @@ void test_copy_if ()
|
|||||||
|
|
||||||
// Copy_if_backward from constant iterators
|
// Copy_if_backward from constant iterators
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsEven );
|
bas::copy_backward_if ( vals2, vals2 + vals2Size, std::back_inserter(res), IsEven );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 8 );
|
BOOST_CHECK_EQUAL ( res[0], 8 );
|
||||||
BOOST_CHECK_EQUAL ( res[1], 6 );
|
BOOST_CHECK_EQUAL ( res[1], 6 );
|
||||||
@ -85,19 +87,19 @@ void test_copy_if ()
|
|||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> );
|
bas::copy_backward_if ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( vals2Size, res.size ());
|
BOOST_CHECK_EQUAL ( vals2Size, res.size ());
|
||||||
BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ()));
|
BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_backward_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
|
|
||||||
// Copy_if_backward using ranges
|
// Copy_if_backward using ranges
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( cont, std::back_inserter(res), IsEven );
|
bas::copy_backward_if ( cont, std::back_inserter(res), IsEven );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
BOOST_CHECK_EQUAL ( res.size (), 5U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 8 );
|
BOOST_CHECK_EQUAL ( res[0], 8 );
|
||||||
BOOST_CHECK_EQUAL ( res[1], 6 );
|
BOOST_CHECK_EQUAL ( res[1], 6 );
|
||||||
@ -107,13 +109,13 @@ void test_copy_if ()
|
|||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( cont, std::back_inserter(res), IsLess<100> );
|
bas::copy_backward_if ( cont, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
||||||
BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ()));
|
BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_if_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_backward_if ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,36 +132,36 @@ void test_copy_while ()
|
|||||||
|
|
||||||
// Copy_while from constant iterators
|
// Copy_while from constant iterators
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> );
|
bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsEqual<0> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 1U );
|
BOOST_CHECK_EQUAL ( res.size (), 1U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 0 );
|
BOOST_CHECK_EQUAL ( res[0], 0 );
|
||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> );
|
bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( valsSize, res.size ());
|
BOOST_CHECK_EQUAL ( valsSize, res.size ());
|
||||||
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
// Copy_while using ranges
|
// Copy_while using ranges
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( cont, std::back_inserter(res), IsNotEqual<1> );
|
bas::copy_while ( cont, std::back_inserter(res), IsNotEqual<1> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 1U );
|
BOOST_CHECK_EQUAL ( res.size (), 1U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 0 );
|
BOOST_CHECK_EQUAL ( res[0], 0 );
|
||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( cont, std::back_inserter(res), IsNotEqual<2> );
|
bas::copy_while ( cont, std::back_inserter(res), IsNotEqual<2> );
|
||||||
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
||||||
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while ( cont, std::back_inserter(res), IsEqual<2> );
|
bas::copy_while ( cont, std::back_inserter(res), IsEqual<2> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
// ---- Backwards tests ----
|
// ---- Backwards tests ----
|
||||||
@ -172,7 +174,7 @@ void test_copy_while ()
|
|||||||
|
|
||||||
// Copy_if_backward from constant iterators
|
// Copy_if_backward from constant iterators
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsGreater<5> );
|
bas::copy_backward_while ( vals2, vals2 + vals2Size, std::back_inserter(res), IsGreater<5> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 4U );
|
BOOST_CHECK_EQUAL ( res.size (), 4U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 9 );
|
BOOST_CHECK_EQUAL ( res[0], 9 );
|
||||||
BOOST_CHECK_EQUAL ( res[1], 8 );
|
BOOST_CHECK_EQUAL ( res[1], 8 );
|
||||||
@ -181,19 +183,19 @@ void test_copy_while ()
|
|||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> );
|
bas::copy_backward_while ( vals2, vals2 + vals2Size, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( vals2Size, res.size ());
|
BOOST_CHECK_EQUAL ( vals2Size, res.size ());
|
||||||
BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ()));
|
BOOST_CHECK ( std::equal ( vals2, vals2 + vals2Size, res.rbegin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_backward_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
|
|
||||||
// Copy_while_backward using ranges
|
// Copy_while_backward using ranges
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( cont, std::back_inserter(res), IsGreater<5> );
|
bas::copy_backward_while ( cont, std::back_inserter(res), IsGreater<5> );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), 3U );
|
BOOST_CHECK_EQUAL ( res.size (), 3U );
|
||||||
BOOST_CHECK_EQUAL ( res[0], 8 );
|
BOOST_CHECK_EQUAL ( res[0], 8 );
|
||||||
BOOST_CHECK_EQUAL ( res[1], 7 );
|
BOOST_CHECK_EQUAL ( res[1], 7 );
|
||||||
@ -201,13 +203,13 @@ void test_copy_while ()
|
|||||||
|
|
||||||
// Copy them all
|
// Copy them all
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( cont, std::back_inserter(res), IsLess<100> );
|
bas::copy_backward_while ( cont, std::back_inserter(res), IsLess<100> );
|
||||||
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
BOOST_CHECK_EQUAL ( cont.size (), res.size ());
|
||||||
BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ()));
|
BOOST_CHECK ( std::equal ( cont.rbegin (), cont.rend (), res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_while_backward ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
bas::copy_backward_while ( vals, vals + valsSize, std::back_inserter(res), IsGreater<100> );
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,18 +226,18 @@ void test_copy_n ()
|
|||||||
|
|
||||||
// copy_n from constant iterators
|
// copy_n from constant iterators
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_n ( vals, valsSize, std::back_inserter(res));
|
bas::copy_n ( vals, valsSize, std::back_inserter(res));
|
||||||
BOOST_CHECK_EQUAL ( res.size (), valsSize );
|
BOOST_CHECK_EQUAL ( res.size (), valsSize );
|
||||||
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
BOOST_CHECK ( std::equal ( vals, vals + valsSize, res.begin ()));
|
||||||
|
|
||||||
// Copy none
|
// Copy none
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_n ( vals, 0, std::back_inserter(res));
|
bas::copy_n ( vals, 0, std::back_inserter(res));
|
||||||
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
BOOST_CHECK_EQUAL ( 0U, res.size ());
|
||||||
|
|
||||||
// Copy_while from container
|
// Copy_while from container
|
||||||
res.clear ();
|
res.clear ();
|
||||||
boost::algorithm::copy_n ( cont.begin (), cont.size (), std::back_inserter(res) );
|
bas::copy_n ( cont.begin (), cont.size (), std::back_inserter(res) );
|
||||||
BOOST_CHECK_EQUAL ( res.size (), cont.size ());
|
BOOST_CHECK_EQUAL ( res.size (), cont.size ());
|
||||||
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
BOOST_CHECK ( std::equal ( cont.begin (), cont.end (), res.begin ()));
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#define BOOST_ALGORITHM_SEQUENCE_COPY_HPP
|
#define BOOST_ALGORITHM_SEQUENCE_COPY_HPP
|
||||||
|
|
||||||
#include <boost/range.hpp> // For boost::begin and boost::end
|
#include <boost/range.hpp> // For boost::begin and boost::end
|
||||||
|
#include <iterator> // for std::iterator_traits<>
|
||||||
|
|
||||||
/// \file copy.hpp
|
/// \file copy.hpp
|
||||||
/// \brief Boost implementation of various STL-type copying algorithms
|
/// \brief Boost implementation of various STL-type copying algorithms
|
||||||
@ -199,7 +200,7 @@ template<typename I,typename O>
|
|||||||
// template <typename I, typename Size, typename O>
|
// template <typename I, typename Size, typename O>
|
||||||
// O copy_n ( I first, Size count, O res )
|
// O copy_n ( I first, Size count, O res )
|
||||||
template <typename I, typename O>
|
template <typename I, typename O>
|
||||||
O copy_n ( I first, typename iterator_traits<I>::difference_type count, O res )
|
O copy_n ( I first, typename std::iterator_traits<I>::difference_type count, O res )
|
||||||
{
|
{
|
||||||
while ( count-- > 0 )
|
while ( count-- > 0 )
|
||||||
*res++ = *first++;
|
*res++ = *first++;
|
||||||
|
Reference in New Issue
Block a user