]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/rotate/1.cc
[multiple changes]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / rotate / 1.cc
1 // Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // 25.2.10 rotate
20
21 #include <algorithm>
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
24
25 using __gnu_test::test_container;
26 using __gnu_test::forward_iterator_wrapper;
27 using __gnu_test::bidirectional_iterator_wrapper;
28 using __gnu_test::random_access_iterator_wrapper;
29
30 typedef test_container<int, forward_iterator_wrapper> Fcontainer;
31 typedef test_container<int, bidirectional_iterator_wrapper> Bcontainer;
32 typedef test_container<int, random_access_iterator_wrapper> Rcontainer;
33
34
35
36 void
37 test1()
38 {
39 bool test __attribute__((unused)) = true;
40 int array[]={1};
41 Fcontainer fcon(array, array);
42 Bcontainer bcon(array, array);
43 Rcontainer rcon(array, array);
44 std::rotate(fcon.begin(), fcon.begin(), fcon.end());
45 std::rotate(bcon.begin(), bcon.begin(), bcon.end());
46 std::rotate(rcon.begin(), rcon.begin(), rcon.end());
47 }
48
49 void
50 test2()
51 {
52 bool test __attribute__((unused)) = true;
53 int array[] = {1};
54 Fcontainer fcon(array, array + 1);
55 Bcontainer bcon(array, array + 1);
56 Rcontainer rcon(array, array + 1);
57 std::rotate(fcon.begin(), fcon.begin(), fcon.end());
58 std::rotate(bcon.begin(), bcon.begin(), bcon.end());
59 std::rotate(rcon.begin(), rcon.begin(), rcon.end());
60 std::rotate(fcon.begin(), fcon.end(), fcon.end());
61 std::rotate(bcon.begin(), bcon.end(), bcon.end());
62 std::rotate(rcon.begin(), rcon.end(), rcon.end());
63 }
64
65 void
66 test3()
67 {
68 bool test __attribute__((unused)) = true;
69 int array[] = {1, 2, 3, 4, 5};
70 Fcontainer fcon(array, array + 5);
71 Bcontainer bcon(array, array + 5);
72 Rcontainer rcon(array, array + 5);
73 std::rotate(fcon.begin(), fcon.it(2), fcon.end());
74 VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 5 &&
75 array[3] == 1 && array[4] == 2);
76 std::rotate(bcon.begin(), bcon.it(2), bcon.end());
77 VERIFY(array[0] == 5 && array[1] == 1 && array[2] == 2 &&
78 array[3] == 3 && array[4] == 4);
79 std::rotate(rcon.begin(), rcon.it(2), rcon.end());
80 VERIFY(array[0] == 2 && array[1] == 3 && array[2] == 4 &&
81 array[3] == 5 && array[4] == 1);
82 }
83
84 void
85 test4()
86 {
87 bool test __attribute__((unused)) = true;
88 int array[] = {1, 2, 3, 4};
89 Fcontainer fcon(array, array + 4);
90 Bcontainer bcon(array, array + 4);
91 Rcontainer rcon(array, array + 4);
92
93 std::rotate(fcon.begin(), fcon.it(3), fcon.end());
94 VERIFY(array[0] == 4 && array[1] == 1 && array[2] == 2 &&
95 array[3] == 3);
96
97 std::rotate(bcon.begin(), bcon.it(3), bcon.end());
98 VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 1 &&
99 array[3] == 2);
100
101 std::rotate(rcon.begin(), rcon.it(3), rcon.end());
102 VERIFY(array[0] == 2 && array[1] == 3 && array[2] == 4 &&
103 array[3] == 1);
104
105 }
106
107 void
108 test5()
109 {
110 bool test __attribute__((unused)) = true;
111 int array[] = {1, 2, 3, 4};
112 Rcontainer con(array, array + 4);
113 std::rotate(con.begin(), con.it(2), con.end());
114 VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 1 &&
115 array[3] == 2);
116 }
117
118 int
119 main()
120 {
121 test1();
122 test2();
123 test3();
124 test4();
125 test5();
126 }