3 // Copyright Neil Groves 2009. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/range/algorithm/adjacent_find.hpp>
12 #include <boost/range/iterator_range.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
26 template< class Container
>
27 void test_adjacent_find_impl()
29 using namespace boost::assign
;
31 typedef BOOST_DEDUCED_TYPENAME
Container::iterator iterator_t
;
32 typedef BOOST_DEDUCED_TYPENAME
Container::const_iterator const_iterator_t
;
35 const Container
& cref_cont
= cont
;
37 std::equal_to
<int> pred
;
39 BOOST_CHECK( boost::adjacent_find(cont
) == cont
.end() );
40 BOOST_CHECK( boost::adjacent_find(cref_cont
) == cref_cont
.end() );
41 BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont
)) == cont
.end() );
42 BOOST_CHECK( boost::adjacent_find(cont
, pred
) == cont
.end() );
43 BOOST_CHECK( boost::adjacent_find(cref_cont
, pred
) == cref_cont
.end() );
44 BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont
), pred
) == cont
.end() );
47 BOOST_CHECK( boost::adjacent_find(cont
) == cont
.end() );
48 BOOST_CHECK( boost::adjacent_find(cref_cont
) == cref_cont
.end() );
49 BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont
)) == cont
.end() );
50 BOOST_CHECK( boost::adjacent_find(cont
, pred
) == cont
.end() );
51 BOOST_CHECK( boost::adjacent_find(cref_cont
, pred
) == cref_cont
.end() );
52 BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont
), pred
) == cont
.end() );
54 cont
+= 2,3,4,5,5,5,6,7,8,9;
55 iterator_t it
= boost::adjacent_find(cont
);
56 iterator_t it_pred
= boost::adjacent_find(cont
, pred
);
57 BOOST_CHECK( it
== it_pred
);
58 BOOST_CHECK( it
!= cont
.end() );
59 BOOST_CHECK( it
== std::adjacent_find(cont
.begin(), cont
.end()) );
62 BOOST_CHECK( *it
== 5 );
64 BOOST_CHECK( it
== boost::adjacent_find(boost::make_iterator_range(cont
)) );
65 BOOST_CHECK( it_pred
== boost::adjacent_find(boost::make_iterator_range(cont
), pred
) );
66 const_iterator_t cit
= boost::adjacent_find(cref_cont
);
67 const_iterator_t cit_pred
= boost::adjacent_find(cref_cont
, pred
);
68 BOOST_CHECK( cit
== cit_pred
);
69 BOOST_CHECK( cit
!= cref_cont
.end() );
70 BOOST_CHECK( cit
== std::adjacent_find(cref_cont
.begin(), cref_cont
.end()) );
71 if (cit
!= cref_cont
.end())
73 BOOST_CHECK( *cit
== 5 );
77 void test_adjacent_find()
79 test_adjacent_find_impl
< std::vector
<int> >();
80 test_adjacent_find_impl
< std::list
<int> >();
81 test_adjacent_find_impl
< std::multiset
<int> >();
86 boost::unit_test::test_suite
*
87 init_unit_test_suite(int argc
, char* argv
[])
89 boost::unit_test::test_suite
* test
90 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.adjacent_find" );
92 test
->add( BOOST_TEST_CASE( &boost::test_adjacent_find
) );