match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
[gcc.git] / libstdc++-v3 / testsuite / util / testsuite_containergen.h
blob25a454d11cfef36873ade41157dc3debecd972c0
1 // Copyright (C) 2013-2025 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.
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.
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/>.
18 #ifndef _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
19 #define _GLIBCXX_TESTSUITE_CONTAINER_GEN_H
21 #include <testsuite_container_traits.h>
22 #include <random>
23 #include <cstdlib> // getenv, atoi
24 #include <cstdio> // printf, fflush
26 namespace __gnu_test
28 template<typename ContainerType, typename Tester, typename RandomGen>
29 void
30 test_single_container(Tester test, RandomGen& rg, int length, int domain)
32 std::vector<int> values;
33 auto dist = std::uniform_int_distribution<>(0, domain - 1);
35 for(int i = 0; i < length; ++i)
36 values.push_back(dist(rg));
38 ContainerType con(values.data(), values.data() + length);
39 test(con, rg);
42 template<typename ContainerType, typename Tester, typename RandomGen>
43 void
44 test_special_containers(Tester test, RandomGen& rg, int length)
46 std::vector<int> values(length);
47 ContainerType con(values.data(), values.data() + length);
49 for(int i = 0; i < length; ++i)
50 values[i] = 0;
51 test(con, rg);
53 for(int i = 0; i < length; ++i)
54 values[i] = i;
55 test(con, rg);
57 for(int i = 0; i < length; ++i)
58 values[i] = -i;
59 test(con, rg);
62 template<typename ContainerType, typename Tester>
63 void
64 test_containers(Tester test)
66 std::mt19937_64 random_gen;
68 if (const char* v = std::getenv("GLIBCXX_SEED_TEST_RNG"))
70 // A single seed value is much smaller than the mt19937 state size,
71 // but we're not trying to be cryptographically secure here.
72 int s = std::atoi(v);
73 if (s == 0)
74 s = (int)std::random_device{}();
75 std::printf("Using random seed %d\n", s);
76 std::fflush(stdout);
77 random_gen.seed((unsigned)s);
80 #ifdef SIMULATOR_TEST
81 int loops = 10;
82 #else
83 int loops = 1000;
84 #endif
86 for(int i = 0; i < loops; ++i)
87 test_special_containers<ContainerType>(test, random_gen, i);
89 for(int i = 1; i < 100; ++i)
90 for(int j = 0; j < loops; ++j)
91 test_single_container<ContainerType>(test, random_gen, i, i);
93 for(int i = 0; i < loops; ++i)
95 test_single_container<ContainerType>(test, random_gen, 10, 10);
96 test_single_container<ContainerType>(test, random_gen, 100, 10);
97 test_single_container<ContainerType>(test, random_gen, 1000, 10);
98 test_single_container<ContainerType>(test, random_gen, 10, 1000);
101 #ifndef SIMULATOR_TEST
102 for(int i = 0; i < 1000; ++i)
104 test_single_container<ContainerType>(test, random_gen, 10000, 10);
105 test_single_container<ContainerType>(test, random_gen, 10000, 10000);
107 #endif
109 } // namespace __gnu_test
111 #endif