Self-test implementations.
197 {
199
200 const float threshold = 1e-3f;
201
203 assert(std::abs(dist.expected_value() - 3.33333333f) < threshold);
204 assert(std::abs(dist.variance() - 7.77777777f) < threshold);
205 assert(std::abs(dist.standard_deviation() - 2.788866755) < threshold);
206 assert(std::abs(dist.probability_density(5) - 0.07203) < threshold);
207 assert(std::abs(dist.cumulative_distribution(6) - 0.882351) < threshold);
208 assert(std::abs(dist.inverse_cumulative_distribution(
209 dist.cumulative_distribution(8)) -
210 8) < threshold);
211 assert(std::abs(dist.range_tries() - 1.0f) < threshold);
212 assert(std::abs(dist.range_tries(3) - 0.49f) < threshold);
213 assert(std::abs(dist.range_tries(5, 11) - 0.2203267f) < threshold);
216
218
220 assert(std::abs(dist.expected_value() - 2.0f) < threshold);
221 assert(std::abs(dist.variance() - 2.0f) < threshold);
222 assert(std::abs(dist.standard_deviation() - 1.4142135f) < threshold);
223 assert(std::abs(dist.probability_density(5) - 0.03125) < threshold);
224 assert(std::abs(dist.cumulative_distribution(6) - 0.984375) < threshold);
225 assert(std::abs(dist.inverse_cumulative_distribution(
226 dist.cumulative_distribution(8)) -
227 8) < threshold);
228 assert(std::abs(dist.range_tries() - 1.0f) < threshold);
229 assert(std::abs(dist.range_tries(3) - 0.25f) < threshold);
230 assert(std::abs(dist.range_tries(5, 11) - 0.062011f) < threshold);
233
235
237 assert(std::abs(dist.expected_value() - 1.25f) < threshold);
238 assert(std::abs(dist.variance() - 0.3125f) < threshold);
239 assert(std::abs(dist.standard_deviation() - 0.559016f) < threshold);
240 assert(std::abs(dist.probability_density(5) - 0.00128) < threshold);
241 assert(std::abs(dist.cumulative_distribution(6) - 0.999936) < threshold);
242 assert(std::abs(dist.inverse_cumulative_distribution(
243 dist.cumulative_distribution(8)) -
244 8) < threshold);
245 assert(std::abs(dist.range_tries() - 1.0f) < threshold);
246 assert(std::abs(dist.range_tries(3) - 0.04f) < threshold);
247 assert(std::abs(dist.range_tries(5, 11) - 0.00159997f) < threshold);
250}
A class to model the geometric distribution.
Definition geometric_dist.cpp:55
void sample_test(const probability::geometric_dist::geometric_distribution &dist)
Tests the sampling method of the geometric distribution.
Definition geometric_dist.cpp:165