1// Boost.Range library
2//
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)
7//
8//
9// For more information, see http://www.boost.org/libs/range/
10//
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>
15
16#include <boost/assign.hpp>
17#include <algorithm>
18#include <list>
19#include <set>
20#include <vector>
21
22namespace boost
23{
24 namespace
25 {
26 template< class Container >
27 void test_adjacent_find_impl()
28 {
29 using namespace boost::assign;
30
31 typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
32 typedef BOOST_DEDUCED_TYPENAME Container::const_iterator const_iterator_t;
33
34 Container cont;
35 const Container& cref_cont = cont;
36
37 std::equal_to<int> pred;
38
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() );
45
46 cont += 1;
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() );
53
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()) );
60 if (it != cont.end())
61 {
62 BOOST_CHECK( *it == 5 );
63 }
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())
72 {
73 BOOST_CHECK( *cit == 5 );
74 }
75 }
76
77 void test_adjacent_find()
78 {
79 test_adjacent_find_impl< std::vector<int> >();
80 test_adjacent_find_impl< std::list<int> >();
81 test_adjacent_find_impl< std::multiset<int> >();
82 }
83 }
84}
85
86boost::unit_test::test_suite*
87init_unit_test_suite(int argc, char* argv[])
88{
89 boost::unit_test::test_suite* test
90 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.adjacent_find" );
91
92 test->add( BOOST_TEST_CASE( &boost::test_adjacent_find ) );
93
94 return test;
95}
96

source code of boost/libs/range/test/algorithm_test/adjacent_find.cpp