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