]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/count_if.cpp
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/count_if.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
17 #include "../test_function/false_predicate.hpp"
18 #include "../test_function/true_predicate.hpp"
19 #include "../test_function/equal_to_x.hpp"
29 template< class Container
>
30 void test_count_if_impl()
32 using namespace boost::range_test_function
;
33 using namespace boost::assign
;
35 typedef equal_to_x
<int> pred_t
;
36 typedef BOOST_DEDUCED_TYPENAME
std::iterator_traits
<BOOST_DEDUCED_TYPENAME
Container::iterator
>::difference_type diff_t
;
39 const Container
& cref_cont
= cont
;
41 BOOST_CHECK_EQUAL( 0u, boost::count_if(cont
, pred_t(0)) );
42 BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont
, pred_t(0)) );
43 BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont
), pred_t(0)) );
46 BOOST_CHECK_EQUAL( 0u, boost::count_if(cont
, pred_t(0)) );
47 BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont
, pred_t(0)) );
48 BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont
), pred_t(0)) );
49 BOOST_CHECK_EQUAL( 1u, boost::count_if(cont
, pred_t(1)) );
50 BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont
, pred_t(1)) );
51 BOOST_CHECK_EQUAL( 1u, boost::count_if(boost::make_iterator_range(cont
), pred_t(1)) );
53 cont
+= 2,3,4,5,6,7,8,9;
54 BOOST_CHECK_EQUAL( 0u, boost::count_if(cont
, pred_t(0)) );
55 BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont
, pred_t(0)) );
56 BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont
), pred_t(0)) );
57 BOOST_CHECK_EQUAL( 1u, boost::count_if(cont
, pred_t(1)) );
58 BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont
, pred_t(1)) );
59 BOOST_CHECK_EQUAL( 1u, boost::count_if(boost::make_iterator_range(cont
), pred_t(1)) );
62 BOOST_CHECK_EQUAL( 0u, boost::count_if(cont
, pred_t(0)) );
63 BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont
, pred_t(0)) );
64 BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont
), pred_t(0)) );
65 BOOST_CHECK_EQUAL( 1u, boost::count_if(cont
, pred_t(1)) );
66 BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont
, pred_t(1)) );
67 BOOST_CHECK_EQUAL( 1u, boost::count_if(boost::make_iterator_range(cont
), pred_t(1)) );
68 BOOST_CHECK_EQUAL( 2u, boost::count_if(cont
, pred_t(2)) );
69 BOOST_CHECK_EQUAL( 2u, boost::count_if(cref_cont
, pred_t(2)) );
70 BOOST_CHECK_EQUAL( 2u, boost::count_if(boost::make_iterator_range(cont
), pred_t(2)) );
72 BOOST_CHECK_EQUAL( 0u, boost::count_if(cont
, false_predicate()) );
73 BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont
, false_predicate()) );
74 BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont
), false_predicate()) );
76 BOOST_CHECK_EQUAL( static_cast<diff_t
>(cont
.size()), boost::count_if(cont
, true_predicate()) );
77 BOOST_CHECK_EQUAL( static_cast<diff_t
>(cont
.size()), boost::count_if(cref_cont
, true_predicate()) );
78 BOOST_CHECK_EQUAL( static_cast<diff_t
>(cont
.size()), boost::count_if(boost::make_iterator_range(cont
), true_predicate()) );
83 test_count_if_impl
< std::vector
<int> >();
84 test_count_if_impl
< std::list
<int> >();
85 test_count_if_impl
< std::multiset
<int> >();
91 boost::unit_test::test_suite
*
92 init_unit_test_suite(int argc
, char* argv
[])
94 boost::unit_test::test_suite
* test
95 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count_if" );
97 test
->add( BOOST_TEST_CASE( &boost::test_count_if
) );