summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/testsuite/25_algorithms
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-09 18:30:11 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-09 18:30:11 +0000
commitf2fed5bcaafbe302593e408f551a79656fa92fae (patch)
tree495b5d52a3e445f1c4f2f20a48bddbe219fc335c /libstdc++-v3/testsuite/25_algorithms
parente030f9cc67a888009cbccb9b202e9e4e0a93c9b0 (diff)
downloadppe42-gcc-f2fed5bcaafbe302593e408f551a79656fa92fae.tar.gz
ppe42-gcc-f2fed5bcaafbe302593e408f551a79656fa92fae.zip
2011-03-09 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/util/testsuite_rvalref.h: Minor tweaks. 2011-03-09 Jonathan Wakely <redi@gcc.gnu.org> Chris Jefferson <chris@bubblescope.net> Paolo Carlini <paolo.carlini@oracle.com> * testsuite/util/testsuite_rvalref.h (rvalstruct_compare_by_value): New. * testsuite/25_algorithms/sort_heap/check_compare_by_value.cc: Likewise. * testsuite/25_algorithms/partial_sort/check_compare_by_value: Likewise. * testsuite/25_algorithms/stable_sort/check_compare_by_value.cc: Likewise. * testsuite/25_algorithms/sort/check_compare_by_value: Likewise. 2011-03-09 Chris Jefferson <chris@bubblescope.net> PR libstdc++/48038 * include/bits/stl_algo.h (__merge_backward): Rename to __move_merge_backward and change to always move rather than copy. (__move_merge): New function similar to std::merge except values are moved instead of copied. (__merge_adaptive, __merge_sort_loop): Change from using std::merge and __merge_backward to __move_merge and __move_merge_backward. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170827 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms')
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/partial_sort/check_compare_by_value.cc93
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/sort/check_compare_by_value.cc86
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/sort_heap/check_compare_by_value.cc88
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/stable_sort/check_compare_by_value.cc90
4 files changed, 357 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/check_compare_by_value.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/check_compare_by_value.cc
new file mode 100644
index 00000000000..e6bb20f6b25
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort/check_compare_by_value.cc
@@ -0,0 +1,93 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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.3.1.3 [lib.partial.sort]
+
+#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::random_access_iterator_wrapper;
+
+typedef __gnu_test::rvalstruct_compare_by_value V;
+typedef test_container<V, random_access_iterator_wrapper> Container;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::partial_sort(con.begin(), con.begin() + 10, con.end());
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < 10; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+ for(int i = 10; i < N; ++i)
+ VERIFY( s1[i].val > s1[9].val && s1[i].ok );
+
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::partial_sort(con.begin(), con.begin() + 10, con.end(),
+ __gnu_test::order);
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < 10; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+ for(int i = 10; i < N; ++i)
+ VERIFY( s1[i].val > s1[9].val && s1[i].ok );
+}
+
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ V vvs[] = { 2, 0 };
+ std::partial_sort(vvs, vvs + 2, vvs + 2);
+ VERIFY( vvs[0].ok && vvs[0].val == 0 );
+ VERIFY( vvs[1].ok && vvs[1].val == 2 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/check_compare_by_value.cc b/libstdc++-v3/testsuite/25_algorithms/sort/check_compare_by_value.cc
new file mode 100644
index 00000000000..ac3e2f7d4ef
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/sort/check_compare_by_value.cc
@@ -0,0 +1,86 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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.3.1 algorithms, sort
+
+#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::random_access_iterator_wrapper;
+
+typedef __gnu_test::rvalstruct_compare_by_value V;
+typedef test_container<V, random_access_iterator_wrapper> Container;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::sort(con.begin(), con.end());
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::sort(con.begin(), con.end(), __gnu_test::order);
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+}
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ V vvs[] = { 2, 0 };
+ std::sort(vvs, vvs + 2);
+ VERIFY( vvs[0].ok && vvs[0].val == 0 );
+ VERIFY( vvs[1].ok && vvs[1].val == 2 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort_heap/check_compare_by_value.cc b/libstdc++-v3/testsuite/25_algorithms/sort_heap/check_compare_by_value.cc
new file mode 100644
index 00000000000..32cff8fd854
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/sort_heap/check_compare_by_value.cc
@@ -0,0 +1,88 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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/>.
+
+#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::random_access_iterator_wrapper;
+
+typedef __gnu_test::rvalstruct_compare_by_value V;
+typedef test_container<V, random_access_iterator_wrapper> Container;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::make_heap(con.begin(), con.end());
+ std::sort_heap(con.begin(), con.end());
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::make_heap(con.begin(), con.end(), __gnu_test::order);
+ std::sort_heap(con.begin(), con.end(), __gnu_test::order);
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+}
+
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ V vvs[] = { 2, 0 };
+ std::make_heap(vvs, vvs + 2);
+ std::sort_heap(vvs, vvs + 2);
+ VERIFY( vvs[0].ok && vvs[0].val == 0 );
+ VERIFY( vvs[1].ok && vvs[1].val == 2 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_sort/check_compare_by_value.cc b/libstdc++-v3/testsuite/25_algorithms/stable_sort/check_compare_by_value.cc
new file mode 100644
index 00000000000..817468c1685
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/stable_sort/check_compare_by_value.cc
@@ -0,0 +1,90 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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.3.1.2 [lib.stable.sort]
+
+#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::random_access_iterator_wrapper;
+
+typedef __gnu_test::rvalstruct_compare_by_value V;
+typedef test_container<V, random_access_iterator_wrapper> Container;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::stable_sort(con.begin(), con.end());
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ {
+ VERIFY( s1[i].val > s1[i - 1].val);
+ VERIFY( s1[i].ok );
+ }
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ V s1[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
+ 17, 8, 18, 9, 19 };
+ const int N = sizeof(s1) / sizeof(V);
+ Container con(s1, s1 + N);
+ std::stable_sort(con.begin(), con.end(), __gnu_test::order);
+ VERIFY( s1[0].ok );
+ for(int i = 1; i < N; ++i)
+ VERIFY( s1[i].val > s1[i - 1].val && s1[i].ok );
+}
+
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ V vvs[] = { 2, 0 };
+ std::stable_sort(vvs, vvs + 2);
+ VERIFY( vvs[0].ok && vvs[0].val == 0 );
+ VERIFY( vvs[1].ok && vvs[1].val == 2 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ return 0;
+}
OpenPOWER on IntegriCloud