]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_containergen.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_containergen.h
1 // Copyright (C) 2013-2016 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 terms
5 // of the GNU General Public License as published by the Free Software
6 // Foundation; either version 3, or (at your option) any later
7 // version.
8
9 // This library is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 #ifndef _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
19 #define _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
20
21 #include <testsuite_container_traits.h>
22 #include <random>
23
24 namespace __gnu_test
25 {
26 template<typename ContainerType, typename Tester, typename RandomGen>
27 void
28 test_single_container(Tester test, RandomGen& rg, int length, int domain)
29 {
30 std::vector<int> values;
31 auto dist = std::uniform_int_distribution<>(0, domain - 1);
32
33 for(int i = 0; i < length; ++i)
34 values.push_back(dist(rg));
35
36 ContainerType con(values.data(), values.data() + length);
37 test(con, rg);
38 }
39
40 template<typename ContainerType, typename Tester, typename RandomGen>
41 void
42 test_special_containers(Tester test, RandomGen& rg, int length)
43 {
44 std::vector<int> values(length);
45 ContainerType con(values.data(), values.data() + length);
46
47 for(int i = 0; i < length; ++i)
48 values[i] = 0;
49 test(con, rg);
50
51 for(int i = 0; i < length; ++i)
52 values[i] = i;
53 test(con, rg);
54
55 for(int i = 0; i < length; ++i)
56 values[i] = -i;
57 test(con, rg);
58 }
59
60 template<typename ContainerType, typename Tester>
61 void
62 test_containers(Tester test)
63 {
64 std::mt19937_64 random_gen;
65
66 #ifdef SIMULATOR_TEST
67 int loops = 10;
68 #else
69 int loops = 1000;
70 #endif
71
72 for(int i = 0; i < loops; ++i)
73 test_special_containers<ContainerType>(test, random_gen, i);
74
75 for(int i = 1; i < 100; ++i)
76 for(int j = 0; j < loops; ++j)
77 test_single_container<ContainerType>(test, random_gen, i, i);
78
79 for(int i = 0; i < loops; ++i)
80 {
81 test_single_container<ContainerType>(test, random_gen, 10, 10);
82 test_single_container<ContainerType>(test, random_gen, 100, 10);
83 test_single_container<ContainerType>(test, random_gen, 1000, 10);
84 test_single_container<ContainerType>(test, random_gen, 10, 1000);
85 }
86
87 #ifndef SIMULATOR_TEST
88 for(int i = 0; i < 1000; ++i)
89 {
90 test_single_container<ContainerType>(test, random_gen, 10000, 10);
91 test_single_container<ContainerType>(test, random_gen, 10000, 10000);
92 }
93 #endif
94 }
95 } // namespace __gnu_test
96
97 #endif