diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-06-25 22:59:01 +0000 |
---|---|---|
committer | <> | 2013-09-27 11:49:28 +0000 |
commit | 8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch) | |
tree | c09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/algorithm/test/is_partitioned_test1.cpp | |
download | boost-tarball-baserock/morph.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/algorithm/test/is_partitioned_test1.cpp')
-rw-r--r-- | libs/algorithm/test/is_partitioned_test1.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libs/algorithm/test/is_partitioned_test1.cpp b/libs/algorithm/test/is_partitioned_test1.cpp new file mode 100644 index 000000000..835de2df9 --- /dev/null +++ b/libs/algorithm/test/is_partitioned_test1.cpp @@ -0,0 +1,64 @@ +/* + Copyright (c) Marshall Clow 2011-2012. + + 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/cxx11/is_partitioned.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 ( v, less_than<int>(3))); // no elements + BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(6))); // only the first element + BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(10))); // in the middle somewhere + BOOST_CHECK ( ba::is_partitioned ( v, less_than<int>(99))); // 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 ( l.begin (), l.end (), less_than<int>(3))); // no elements + BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(6))); // only the first element + BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(10))); // in the middle somewhere + BOOST_CHECK ( ba::is_partitioned ( l.begin (), l.end (), less_than<int>(99))); // all elements satisfy + } + + +BOOST_AUTO_TEST_CASE( test_main ) +{ + test_sequence1 (); +} |