summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/testsuite/25_algorithms
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-23 22:19:30 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-23 22:19:30 +0000
commitbf7468d8dc5ad97be65cc19bb65c59ea5cfbca34 (patch)
tree0304deb2a42e816095b6bb7495df375270720ae5 /libstdc++-v3/testsuite/25_algorithms
parent428913f8c6fd022c48e2f588984cb8a25ee2acd8 (diff)
downloadppe42-gcc-bf7468d8dc5ad97be65cc19bb65c59ea5cfbca34.tar.gz
ppe42-gcc-bf7468d8dc5ad97be65cc19bb65c59ea5cfbca34.zip
2013-10-23 Chris Jefferson <chris@bubblescope.net>
Paolo Carlini <paolo.carlini@oracle.com> * testsuite/util/testsuite_containergen.h: New. * testsuite/util/testsuite_iterators.h (test_container<>::val): Add. * testsuite/25_algorithms/nth_element/random_test.cc: New, use the above. * testsuite/25_algorithms/partial_sort/random_test.cc: Likewise. * testsuite/25_algorithms/partial_sort_copy/random_test.cc: Likewise. * testsuite/25_algorithms/sort/random_test.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@203995 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/25_algorithms')
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/nth_element/random_test.cc63
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/partial_sort/random_test.cc62
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/random_test.cc67
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/sort/random_test.cc51
4 files changed, 243 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/25_algorithms/nth_element/random_test.cc b/libstdc++-v3/testsuite/25_algorithms/nth_element/random_test.cc
new file mode 100644
index 00000000000..ef1d0b6c4e6
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/nth_element/random_test.cc
@@ -0,0 +1,63 @@
+// Copyright (C) 2013 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -DSIMULATOR_TEST" { target simulator } }
+// { dg-require-cstdint "" }
+
+// 25.4.2 [lib.alg.nth.element]
+
+#include <algorithm>
+#include <random>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_containergen.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+struct testNthElement
+{
+ template<typename Container, typename RandomGen>
+ void operator()(Container con, RandomGen& rg)
+ {
+ bool test __attribute__((unused)) = true;
+
+ const int size = con.end() - con.begin();
+ auto dist = std::uniform_int_distribution<>(0, size);
+ const int element = dist(rg);
+
+ std::nth_element(con.begin(), con.begin() + element, con.end());
+
+ if (element < size)
+ {
+ for (int i = 0; i < element; ++i)
+ VERIFY( con.val(i) <= con.val(element) );
+
+ for (int i = element + 1; i < size; ++i)
+ VERIFY( con.val(i) >= con.val(element) );
+ }
+ }
+};
+
+int
+main()
+{
+ __gnu_test::test_containers<Container>(testNthElement());
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/random_test.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/random_test.cc
new file mode 100644
index 00000000000..855e92121b3
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort/random_test.cc
@@ -0,0 +1,62 @@
+// Copyright (C) 2013 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -DSIMULATOR_TEST" { target simulator } }
+// { dg-require-cstdint "" }
+
+// 25.4.1.3 [lib.alg.partial.sort]
+
+#include <algorithm>
+#include <random>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_containergen.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+struct testPartialSort
+{
+ template<typename Container, typename RandomGen>
+ void operator()(Container con, RandomGen& rg)
+ {
+ bool test __attribute__((unused)) = true;
+
+ const int size = con.end() - con.begin();
+ auto dist = std::uniform_int_distribution<>(0, size);
+ const int element = dist(rg);
+
+ std::partial_sort(con.begin(), con.begin() + element, con.end());
+
+ VERIFY( std::is_sorted(con.begin(), con.begin() + element) );
+
+ if (element > 0)
+ {
+ for (int i = element; i < size; ++i)
+ VERIFY( con.val(element - 1) <= con.val(i) );
+ }
+ }
+};
+
+int
+main()
+{
+ __gnu_test::test_containers<Container>(testPartialSort());
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/random_test.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/random_test.cc
new file mode 100644
index 00000000000..cca4c568cbb
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/random_test.cc
@@ -0,0 +1,67 @@
+// Copyright (C) 2013 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -DSIMULATOR_TEST" { target simulator } }
+// { dg-require-cstdint "" }
+
+// 25.4.1.4 [lib.alg.partial.sort.copy]
+
+#include <algorithm>
+#include <random>
+#include <vector>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_containergen.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+struct testPartialSortCopy
+{
+ template<typename Container, typename RandomGen>
+ void operator()(Container con, RandomGen& rg)
+ {
+ bool test __attribute__((unused)) = true;
+
+ const int size = con.end() - con.begin();
+ auto dist = std::uniform_int_distribution<>(0, size);
+ const int element = dist(rg);
+
+ std::vector<int> outvec(element + 1); // add +1 to avoid empty issues
+
+ Container out(outvec.data(), outvec.data() + element);
+
+ std::partial_sort_copy(con.begin(), con.end(),
+ out.begin(), out.begin() + element);
+
+ VERIFY( std::is_sorted(out.begin(), out.begin() + element) );
+
+ std::sort(con.begin(), con.end());
+
+ for (int i = 0; i < element; ++i)
+ VERIFY( con.val(i) == out.val(i) );
+ }
+};
+
+int
+main()
+{
+ __gnu_test::test_containers<Container>(testPartialSortCopy());
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/random_test.cc b/libstdc++-v3/testsuite/25_algorithms/sort/random_test.cc
new file mode 100644
index 00000000000..ff3d06aa35c
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/sort/random_test.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2013 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-options "-std=gnu++11 -DSIMULATOR_TEST" { target simulator } }
+// { dg-require-cstdint "" }
+
+// 25.4.1 [lib.alg.sort]
+
+#include <algorithm>
+#include <random>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_containergen.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+struct testSort
+{
+ template<typename Container, typename RandomGen>
+ void operator()(Container con, RandomGen&)
+ {
+ bool test __attribute__((unused)) = true;
+
+ std::sort(con.begin(), con.end());
+ VERIFY( std::is_sorted(con.begin(), con.end()) );
+ }
+};
+
+int
+main()
+{
+ __gnu_test::test_containers<Container>(testSort());
+}
OpenPOWER on IntegriCloud