6#include "../../namespaces.h"
7#include "../../utilities/statistics/percentages.h"
8#include "../../utilities/semantics/generator_handler.h"
10#include <catch/catch.hpp>
24 std::vector<Catch::Generators::GeneratorWrapper<T>>&& generators,
25 const std::vector<
double>& weights
27 random_engine{
std::random_device{}()},
30 assert(weights.size() ==
this->generators.size());
34 this->generators.begin(),
this->generators.end(),
this->generators.begin(),
41 T
const&
get()
const override {
return current_value; }
44 std::size_t generator_index{choice_distribution(random_engine)};
46 if (!generators[generator_index].next())
return false;
47 current_value = generators[generator_index].get();
53 std::vector<Catch::Generators::GeneratorWrapper<T>> generators;
55 std::mt19937 random_engine;
56 std::discrete_distribution<
std::size_t> choice_distribution;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
92 std::vector<Catch::Generators::GeneratorWrapper<T>>&& generators,
93 const std::vector<
double>& weights
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
125 std::vector<Catch::Generators::GeneratorWrapper<T>>&& generators
127 std::vector<
double> weights(
131 return oneof(
std::move(generators),
std::move(weights));
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
168 std::vector<Catch::Generators::GeneratorWrapper<T>>&& generators,
169 const std::vector<std::size_t>& amounts
171 std::size_t total_amount{
std::accumulate(amounts.cbegin(), amounts.cend(),
std::size_t{0})};
173 std::vector<
double> weights;
174 weights.reserve(amounts.size());
177 amounts.cbegin(), amounts.cend(),
178 std::back_inserter(weights),
182 return oneof(
std::move(generators),
std::move(weights));
OneOfGenerator(std::vector< Catch::Generators::GeneratorWrapper< T > > &&generators, const std::vector< double > &weights)
T const & get() const override
Catch::Generators::GeneratorWrapper< T > oneof(std::vector< Catch::Generators::GeneratorWrapper< T > > &&generators, const std::vector< double > &weights)
Returns a generator whose set of elements is the union of the set of elements of the generators in ge...
Catch::Generators::GeneratorWrapper< T > uniform_oneof(std::vector< Catch::Generators::GeneratorWrapper< T > > &&generators)
Returns a generator whose set of elements is the union of the set of elements of the generators in ge...
Catch::Generators::GeneratorWrapper< T > uniformly_valued_oneof(std::vector< Catch::Generators::GeneratorWrapper< T > > &&generators, const std::vector< std::size_t > &amounts)
Returns a generator whose set of elements is the union of the set of elements of the generators in ge...
double percent_of(double amount, double total)
Returns the percentage of \amount over total.
#define QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE
#define QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE
#define QDOC_CATCH_GENERATORS_ROOT_NAMESPACE