summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/util
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/util
parent428913f8c6fd022c48e2f588984cb8a25ee2acd8 (diff)
downloadgcc-bf7468d8dc5ad97be65cc19bb65c59ea5cfbca34.tar.gz
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/util')
-rw-r--r--libstdc++-v3/testsuite/util/testsuite_containergen.h97
-rw-r--r--libstdc++-v3/testsuite/util/testsuite_iterators.h4
2 files changed, 101 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/util/testsuite_containergen.h b/libstdc++-v3/testsuite/util/testsuite_containergen.h
new file mode 100644
index 00000000000..ff512ac8a8e
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/testsuite_containergen.h
@@ -0,0 +1,97 @@
+// 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/>.
+
+#ifndef _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
+#define _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
+
+#include <testsuite_container_traits.h>
+#include <random>
+
+namespace __gnu_test
+{
+ template<typename ContainerType, typename Tester, typename RandomGen>
+ void
+ test_single_container(Tester test, RandomGen& rg, int length, int domain)
+ {
+ std::vector<int> values;
+ auto dist = std::uniform_int_distribution<>(0, domain - 1);
+
+ for(int i = 0; i < length; ++i)
+ values.push_back(dist(rg));
+
+ ContainerType con(values.data(), values.data() + length);
+ test(con, rg);
+ }
+
+ template<typename ContainerType, typename Tester, typename RandomGen>
+ void
+ test_special_containers(Tester test, RandomGen& rg, int length)
+ {
+ std::vector<int> values(length);
+ ContainerType con(values.data(), values.data() + length);
+
+ for(int i = 0; i < length; ++i)
+ values[i] = 0;
+ test(con, rg);
+
+ for(int i = 0; i < length; ++i)
+ values[i] = i;
+ test(con, rg);
+
+ for(int i = 0; i < length; ++i)
+ values[i] = -i;
+ test(con, rg);
+ }
+
+ template<typename ContainerType, typename Tester>
+ void
+ test_containers(Tester test)
+ {
+ std::mt19937_64 random_gen;
+
+#ifdef SIMULATOR_TEST
+ int loops = 10;
+#else
+ int loops = 1000;
+#endif
+
+ for(int i = 0; i < loops; ++i)
+ test_special_containers<ContainerType>(test, random_gen, i);
+
+ for(int i = 1; i < 100; ++i)
+ for(int j = 0; j < loops; ++j)
+ test_single_container<ContainerType>(test, random_gen, i, i);
+
+ for(int i = 0; i < loops; ++i)
+ {
+ test_single_container<ContainerType>(test, random_gen, 10, 10);
+ test_single_container<ContainerType>(test, random_gen, 100, 10);
+ test_single_container<ContainerType>(test, random_gen, 1000, 10);
+ test_single_container<ContainerType>(test, random_gen, 10, 1000);
+ }
+
+#ifndef SIMULATOR_TEST
+ for(int i = 0; i < 1000; ++i)
+ {
+ test_single_container<ContainerType>(test, random_gen, 10000, 10);
+ test_single_container<ContainerType>(test, random_gen, 10000, 10000);
+ }
+#endif
+ }
+} // namespace __gnu_test
+
+#endif
diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index 9bb58588651..c9dccb79227 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -539,6 +539,10 @@ namespace __gnu_test
return ItType<T>(pos, &bounds);
}
+ const T&
+ val(int pos)
+ { return (bounds.first)[pos]; }
+
ItType<T>
begin()
{ return it(bounds.first); }