diff options
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms/rotate')
7 files changed, 480 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/1.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/1.cc new file mode 100644 index 000000000..eac096c42 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/1.cc @@ -0,0 +1,125 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.10 rotate + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +using __gnu_test::test_container; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::random_access_iterator_wrapper; + +typedef test_container<int, forward_iterator_wrapper> Fcontainer; +typedef test_container<int, bidirectional_iterator_wrapper> Bcontainer; +typedef test_container<int, random_access_iterator_wrapper> Rcontainer; + + + +void +test1() +{ + bool test __attribute__((unused)) = true; + int array[]={1}; + Fcontainer fcon(array, array); + Bcontainer bcon(array, array); + Rcontainer rcon(array, array); + std::rotate(fcon.begin(), fcon.begin(), fcon.end()); + std::rotate(bcon.begin(), bcon.begin(), bcon.end()); + std::rotate(rcon.begin(), rcon.begin(), rcon.end()); +} + +void +test2() +{ + bool test __attribute__((unused)) = true; + int array[] = {1}; + Fcontainer fcon(array, array + 1); + Bcontainer bcon(array, array + 1); + Rcontainer rcon(array, array + 1); + std::rotate(fcon.begin(), fcon.begin(), fcon.end()); + std::rotate(bcon.begin(), bcon.begin(), bcon.end()); + std::rotate(rcon.begin(), rcon.begin(), rcon.end()); + std::rotate(fcon.begin(), fcon.end(), fcon.end()); + std::rotate(bcon.begin(), bcon.end(), bcon.end()); + std::rotate(rcon.begin(), rcon.end(), rcon.end()); +} + +void +test3() +{ + bool test __attribute__((unused)) = true; + int array[] = {1, 2, 3, 4, 5}; + Fcontainer fcon(array, array + 5); + Bcontainer bcon(array, array + 5); + Rcontainer rcon(array, array + 5); + std::rotate(fcon.begin(), fcon.it(2), fcon.end()); + VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 5 && + array[3] == 1 && array[4] == 2); + std::rotate(bcon.begin(), bcon.it(2), bcon.end()); + VERIFY(array[0] == 5 && array[1] == 1 && array[2] == 2 && + array[3] == 3 && array[4] == 4); + std::rotate(rcon.begin(), rcon.it(2), rcon.end()); + VERIFY(array[0] == 2 && array[1] == 3 && array[2] == 4 && + array[3] == 5 && array[4] == 1); +} + +void +test4() +{ + bool test __attribute__((unused)) = true; + int array[] = {1, 2, 3, 4}; + Fcontainer fcon(array, array + 4); + Bcontainer bcon(array, array + 4); + Rcontainer rcon(array, array + 4); + + std::rotate(fcon.begin(), fcon.it(3), fcon.end()); + VERIFY(array[0] == 4 && array[1] == 1 && array[2] == 2 && + array[3] == 3); + + std::rotate(bcon.begin(), bcon.it(3), bcon.end()); + VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 1 && + array[3] == 2); + + std::rotate(rcon.begin(), rcon.it(3), rcon.end()); + VERIFY(array[0] == 2 && array[1] == 3 && array[2] == 4 && + array[3] == 1); + +} + +void +test5() +{ + bool test __attribute__((unused)) = true; + int array[] = {1, 2, 3, 4}; + Rcontainer con(array, array + 4); + std::rotate(con.begin(), con.it(2), con.end()); + VERIFY(array[0] == 3 && array[1] == 4 && array[2] == 1 && + array[3] == 2); +} + +int +main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/check_type.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/check_type.cc new file mode 100644 index 000000000..ca3a05da0 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/check_type.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.10 Rotate + +// { dg-do compile } + +#include <algorithm> +#include <testsuite_iterators.h> + +struct X { }; + +bool operator<(X,X) { return true;} + +void +test1(__gnu_test::forward_iterator_wrapper<X>& begin, + __gnu_test::forward_iterator_wrapper<X>& middle, + __gnu_test::forward_iterator_wrapper<X>& end) +{ return std::rotate(begin,middle,end); } + +void +test1(__gnu_test::bidirectional_iterator_wrapper<X>& begin, + __gnu_test::bidirectional_iterator_wrapper<X>& middle, + __gnu_test::bidirectional_iterator_wrapper<X>& end) +{ return std::rotate(begin,middle,end); } + +void +test1(__gnu_test::random_access_iterator_wrapper<X>& begin, + __gnu_test::random_access_iterator_wrapper<X>& middle, + __gnu_test::random_access_iterator_wrapper<X>& end) +{ return std::rotate(begin,middle,end); } + + diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/moveable.cc new file mode 100644 index 000000000..ac9e0b309 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/moveable.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.10 rotate + +// Tests rotate when an moveable class is used + +#undef _GLIBCXX_CONCEPT_CHECKS + +// XXX FIXME: parallel-mode should deal correctly with moveable-only types +// per C++0x, at minimum smoothly fall back to serial. +#undef _GLIBCXX_PARALLEL + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer; +typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer; +typedef test_container<rvalstruct, random_access_iterator_wrapper> Rcontainer; + + + +void +test1() +{ + bool test __attribute__((unused)) = true; + int data[] = {1, 2, 3, 4, 5}; + rvalstruct array[5]; + std::copy(data, data + 5, array); + Fcontainer fcon(array, array + 5); + Bcontainer bcon(array, array + 5); + Rcontainer rcon(array, array + 5); + + std::rotate(fcon.begin(), fcon.it(2), fcon.end()); + VERIFY(array[0].val == 3 && array[1].val == 4 && array[2].val == 5 && + array[3].val == 1 && array[4].val == 2); + for(int i=0;i<5;i++) + VERIFY(array[i].valid == true); + + std::rotate(bcon.begin(), bcon.it(2), bcon.end()); + VERIFY(array[0].val == 5 && array[1].val == 1 && array[2].val == 2 && + array[3].val == 3 && array[4].val == 4); + for(int i=0;i<5;i++) + VERIFY(array[i].valid); + + std::rotate(rcon.begin(), rcon.it(2), rcon.end()); + VERIFY(array[0].val == 2 && array[1].val == 3 && array[2].val == 4 && + array[3].val == 5 && array[4].val == 1); + for(int i=0;i<5;i++) + VERIFY(array[i].valid); +} + +int +main() +{ + test1(); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/moveable2.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/moveable2.cc new file mode 100644 index 000000000..d48d6029a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/moveable2.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.2.10 rotate + +// Tests rotate when an moveable class is used + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::forward_iterator_wrapper; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer; +typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer; +typedef test_container<rvalstruct, random_access_iterator_wrapper> Rcontainer; + +template<typename Con> + void + test_con(int length, int rotate_pos) + { + bool test __attribute__((unused)) = true; + + rvalstruct array[length]; + for(int i = 0; i < length; ++i) + array[i] = i; + Con con(array, array + length); + std::rotate(con.begin(), con.it(rotate_pos), con.end()); + + if(length != 0) + { + for(int i = 0; i < length; ++i) + VERIFY( array[i].valid && array[i].val == (i + rotate_pos) % length ); + } + } + +void +test01() +{ + for(int i = 0; i < 20; ++i) + { + for(int j = 0; j <= i; ++j) + { + test_con<Fcontainer>(i, j); + test_con<Bcontainer>(i, j); + test_con<Rcontainer>(i, j); + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..c6aebab34 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/2.cc @@ -0,0 +1,34 @@ +// { dg-do compile } + +// 2007-09-20 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <algorithm> +#include <testsuite_api.h> + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + + template void rotate(iterator_type, iterator_type, iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/pod.cc new file mode 100644 index 000000000..ab65338a0 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,34 @@ +// { dg-do compile } + +// 2007-09-20 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <algorithm> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + + template void rotate(iterator_type, iterator_type, iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/rotate.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/rotate.cc new file mode 100644 index 000000000..31bb88e5d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/rotate.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 25.?? algorithms, rotate() + +#include <algorithm> +#include <testsuite_hooks.h> +#include <list> + +bool test __attribute__((unused)) = true; + +int A[] = {1, 2, 3, 4, 5, 6, 7}; +int B[] = {2, 3, 4, 5, 6, 7, 1}; +int C[] = {1, 2, 3, 4, 5, 6, 7}; +int D[] = {5, 6, 7, 1, 2, 3, 4}; +const int N = sizeof(A) / sizeof(int); + +/* need a test for a forward iterator -- can't think of one that makes sense */ + +/* biderectional iterator */ +void +test02() +{ + using std::rotate; + typedef std::list<int> Container; + + Container a(A, A + N); + VERIFY(std::equal(a.begin(), a.end(), A)); + + Container::iterator i = a.begin(); + rotate(a.begin(), ++i, a.end()); + VERIFY(std::equal(a.begin(), a.end(), B)); + + i = a.end(); + rotate(a.begin(), --i, a.end()); + VERIFY(std::equal(a.begin(), a.end(), C)); + + i = a.begin(); + std::advance(i, 3); + rotate(a.begin(), ++i, a.end()); + VERIFY(std::equal(a.begin(), a.end(), D)); +} + +/* random iterator */ +void +test03() +{ + using std::rotate; + rotate(A, A + 1, A + N); + VERIFY(std::equal(A, A + N, B)); + + rotate(A, A + N - 1, A + N); + VERIFY(std::equal(A, A + N, C)); + + rotate(A, A + 4, A + N); + VERIFY(std::equal(A, A + N, D)); +} + +int +main() +{ + test02(); + test03(); + return 0; +} |