]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/is_permutation/1.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / is_permutation / 1.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // 2011-01-13 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2011-2014 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 25.2.12 [alg.is_permutation] Is permutation
23
24 #include <algorithm>
25 #include <functional>
26 #include <testsuite_hooks.h>
27
28 struct my_equal_to
29 {
30 bool
31 operator()(int __x, int __y) const
32 { return __x % 10 == __y % 10; }
33 };
34
35 const int arr0[] = { 11, 22, 33, 44, 55 };
36
37 void
38 do_test(int arr1[5], bool np = true)
39 {
40 bool test __attribute__((unused)) = true;
41
42 do
43 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0) == np );
44 while (std::next_permutation(arr1, arr1 + 5));
45 }
46
47 template<typename Predicate>
48 void
49 do_test(int arr1[5], Predicate pred, bool np = true)
50 {
51 bool test __attribute__((unused)) = true;
52
53 do
54 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, pred) == np );
55 while (std::next_permutation(arr1, arr1 + 5));
56 }
57
58 void test01()
59 {
60 int arr1[] = { 11, 22, 33, 44, 55 };
61 do_test(arr1);
62
63 int arr2[] = { 11, 33, 33, 44, 55 };
64 do_test(arr2, false);
65
66 int arr3[] = { 33, 33, 33, 44, 44 };
67 do_test(arr3, false);
68
69 int arr4[] = { 11, 22, 33, 44, 55 };
70 do_test(arr4, std::equal_to<int>());
71
72 int arr5[] = { 11, 33, 33, 44, 55 };
73 do_test(arr5, std::equal_to<int>(), false);
74
75 int arr6[] = { 33, 33, 33, 44, 44 };
76 do_test(arr6, std::equal_to<int>(), false);
77
78 int arr7[] = { 1, 2, 3, 4, 5 };
79 do_test(arr7, my_equal_to());
80
81 int arr8[] = { 1, 3, 3, 4, 5 };
82 do_test(arr8, my_equal_to(), false);
83
84 int arr9[] = { 3, 3, 3, 4, 4 };
85 do_test(arr9, my_equal_to(), false);
86
87 int arr10[] = { 111, 222, 333, 444, 555 };
88 do_test(arr10, my_equal_to());
89
90 int arr11[] = { 1, 222, 33, 4, 55 };
91 do_test(arr11, my_equal_to());
92
93 int arr12[] = { 111, 333, 333, 444, 555 };
94 do_test(arr12, my_equal_to(), false);
95
96 int arr13[] = { 333, 333, 333, 444, 444 };
97 do_test(arr13, my_equal_to(), false);
98 }
99
100 int main()
101 {
102 test01();
103 return 0;
104 }