]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/minmax_element/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / minmax_element / 1.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
f6547b68 2
99dee823 3// Copyright (C) 2007-2021 Free Software Foundation, Inc.
f6547b68
PC
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
f6547b68
PC
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
f6547b68
PC
19
20#include <algorithm>
21#include <testsuite_iterators.h>
22#include <testsuite_hooks.h>
23
24using __gnu_test::test_container;
25using __gnu_test::forward_iterator_wrapper;
26using std::minmax_element;
27
28typedef test_container<int, forward_iterator_wrapper> Container;
29typedef std::pair<forward_iterator_wrapper<int>, forward_iterator_wrapper<int> > pair_type;
30
31void
32test1()
33{
f6547b68
PC
34 int array[] = {0};
35 Container con(array, array);
36 pair_type p1 = minmax_element(con.begin(), con.end());
37 VERIFY( p1.first.ptr == array );
38 VERIFY( p1.second.ptr == array );
39}
40
41void
42test2()
43{
f6547b68
PC
44 int array[] = {0};
45 Container con(array, array + 1);
46 pair_type p1 = minmax_element(con.begin(), con.end());
47 VERIFY( p1.first.ptr == array );
48 VERIFY( p1.second.ptr == array );
49}
50
51void
52test3()
53{
f6547b68
PC
54 int array[] = {0, 3};
55 Container con(array, array + 2);
56 pair_type p1 = minmax_element(con.begin(), con.end());
57 VERIFY( p1.first.ptr == array );
58 VERIFY( p1.second.ptr == array + 1 );
59}
60
61void
62test4()
63{
f6547b68
PC
64 int array[] = {3, 0};
65 Container con(array, array + 2);
66 pair_type p1 = minmax_element(con.begin(), con.end());
67 VERIFY( p1.first.ptr == array + 1 );
68 VERIFY( p1.second.ptr == array );
69}
70
71void
72test5()
73{
f6547b68
PC
74 int array[] = {3, 3};
75 Container con(array, array + 2);
76 pair_type p1 = minmax_element(con.begin(), con.end());
77 VERIFY( p1.first.ptr == array );
78 VERIFY( p1.second.ptr == array + 1 );
79}
80
81void
82test6()
83{
f6547b68
PC
84 int array[] = {6, 3, 0, 2, 6, 4, 0};
85 Container con(array, array + 7);
86 pair_type p1 = minmax_element(con.begin(), con.end());
87 VERIFY( p1.first.ptr == array + 2 );
88 VERIFY( p1.second.ptr == array + 4 );
89}
90
91void
92test7()
93{
f6547b68
PC
94 int array[] = {4, 4, 4, 6, 6, 6, 1, 1, 0, 0, 0, 2, 2};
95 Container con(array, array + 13);
96 pair_type p1 = minmax_element(con.begin(), con.end());
97 VERIFY( p1.first.ptr == array + 8 );
98 VERIFY( p1.second.ptr == array + 5 );
99}
100
101void
102test8()
103{
f6547b68
PC
104 int array[] = {1, 7, 5, 5, 10, 1, 0, 0, 8, 4, 4, 0, 10, 10, 10, 1};
105 Container con(array, array + 16);
106 pair_type p1 = minmax_element(con.begin(), con.end());
107 VERIFY( p1.first.ptr == array + 6 );
108 VERIFY( p1.second.ptr == array + 14 );
109}
110
111int main()
112{
113 test1();
114 test2();
115 test3();
116 test4();
117 test5();
118 test6();
119 test7();
120 test8();
121 return 0;
122}