]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/test/is_permutation_test1.cpp
2 Copyright (c) Marshall Clow 2011-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
12 #include <boost/config.hpp>
13 #include <boost/algorithm/cxx11/is_permutation.hpp>
14 #include <boost/algorithm/cxx14/is_permutation.hpp>
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
23 #include "iterator_test.hpp"
26 bool eq ( const T
& a
, const T
& b
) { return a
== b
; }
29 bool never_eq ( const T
&, const T
& ) { return false; }
31 namespace ba
= boost::algorithm
;
33 void test_sequence1 () {
34 int num
[] = { 1, 1, 2, 3, 5 };
35 const int sz
= sizeof (num
)/sizeof(num
[0]);
40 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
),
41 forward_iterator
<int *>(num
)));
44 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
),
45 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
)));
48 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
),
49 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
)));
52 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
),
53 forward_iterator
<int *>(num
),
54 never_eq
<int> )); // Since the sequences are empty, the pred is never called
56 // Empty vs. non-empty
59 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
),
60 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ 1)));
64 forward_iterator
<int *>(num
+ 1), forward_iterator
<int *>(num
+ 2),
65 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
)));
69 random_access_iterator
<int *>(num
+ 1), random_access_iterator
<int *>(num
+ 2),
70 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
)));
74 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
),
75 random_access_iterator
<int *>(num
+ 1), random_access_iterator
<int *>(num
+ 2)));
77 // Something should be a permutation of itself
80 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
81 forward_iterator
<int *>(num
)));
84 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
85 forward_iterator
<int *>(num
), eq
<int> ));
88 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
89 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
)));
92 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
93 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
98 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
+ sz
),
99 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
+ sz
)));
102 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
+ sz
),
103 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
+ sz
),
107 random_access_iterator
<int *>(num
), random_access_iterator
<int *>(num
+ sz
),
108 forward_iterator
<int *>(num
), forward_iterator
<int *>(num
+ sz
),
112 std::vector
<int> v
, v1
;
115 for ( std::size_t i
= 5; i
< 15; ++i
)
118 BOOST_CHECK ( ba::is_permutation ( v
.begin (), v
.end (), v
.begin ())); // better be a permutation of itself!
119 BOOST_CHECK ( ba::is_permutation ( v
.begin (), v
.end (), v1
.begin ()));
121 // With bidirectional iterators.
123 std::copy ( v
.begin (), v
.end (), std::back_inserter ( l
));
124 BOOST_CHECK ( ba::is_permutation ( l
.begin (), l
.end (), l
.begin ())); // better be a permutation of itself!
125 BOOST_CHECK ( ba::is_permutation ( l
.begin (), l
.end (), v1
.begin ()));
126 for ( std::size_t i
= 0; i
< l
.size (); ++i
) {
127 l
.push_back ( *l
.begin ()); l
.pop_front (); // rotation
128 BOOST_CHECK ( ba::is_permutation ( l
.begin (), l
.end (), v1
.begin ()));
133 BOOST_AUTO_TEST_CASE( test_main
)