6#include "ns3/random-variable-stream.h"
7#include "ns3/rng-seed-manager.h"
13#include <gsl/gsl_cdf.h>
14#include <gsl/gsl_histogram.h>
41 double increment = (end - start) / (n - 1.);
77 void DoRun()
override;
81 :
TestCase(
"Uniform Random Number Generator")
92 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
93 gsl_histogram_set_ranges_uniform(h, 0., 1.);
97 gsl_histogram_increment(h, u->GetValue());
106 tmp[i] = gsl_histogram_get(h, i);
112 gsl_histogram_free(h);
114 double chiSquared = 0;
118 chiSquared += tmp[i];
130 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
170 void DoRun()
override;
174 :
TestCase(
"Normal Random Number Generator")
185 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
189 range[0] = -std::numeric_limits<double>::max();
190 range[
N_BINS] = std::numeric_limits<double>::max();
192 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
200 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
206 gsl_histogram_increment(h, n->GetValue());
213 tmp[i] = gsl_histogram_get(h, i);
214 tmp[i] -= expected[i];
216 tmp[i] /= expected[i];
219 gsl_histogram_free(h);
221 double chiSquared = 0;
225 chiSquared += tmp[i];
237 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
277 void DoRun()
override;
281 :
TestCase(
"Exponential Random Number Generator")
292 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
296 range[
N_BINS] = std::numeric_limits<double>::max();
298 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
306 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
312 gsl_histogram_increment(h, e->GetValue());
319 tmp[i] = gsl_histogram_get(h, i);
320 tmp[i] -= expected[i];
322 tmp[i] /= expected[i];
325 gsl_histogram_free(h);
327 double chiSquared = 0;
331 chiSquared += tmp[i];
343 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
383 void DoRun()
override;
387 :
TestCase(
"Pareto Random Number Generator")
398 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
402 range[
N_BINS] = std::numeric_limits<double>::max();
404 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
409 double b = 0.33333333;
415 expected[i] = gsl_cdf_pareto_P(range[i + 1], a, b) - gsl_cdf_pareto_P(range[i], a, b);
421 gsl_histogram_increment(h, p->GetValue());
428 tmp[i] = gsl_histogram_get(h, i);
429 tmp[i] -= expected[i];
431 tmp[i] /= expected[i];
434 gsl_histogram_free(h);
436 double chiSquared = 0;
440 chiSquared += tmp[i];
452 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
Test case for exponential distribution random number generator.
~RngExponentialTestCase() override
static const uint32_t N_BINS
Number of bins.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_MEASUREMENTS
Number of measurements.
double ChiSquaredTest(Ptr< ExponentialRandomVariable > n)
Run a chi-squared test on the results of the random number generator.
static const uint32_t N_RUNS
Number of runs.
Test case for normal distribution random number generator.
~RngNormalTestCase() override
double ChiSquaredTest(Ptr< NormalRandomVariable > n)
Run a chi-squared test on the results of the random number generator.
static const uint32_t N_MEASUREMENTS
Number of measurements.
static const uint32_t N_RUNS
Number of runs.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_BINS
Number of bins.
Test case for pareto distribution random number generator.
static const uint32_t N_RUNS
Number of runs.
~RngParetoTestCase() override
double ChiSquaredTest(Ptr< ParetoRandomVariable > p)
Run a chi-squared test on the results of the random number generator.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_BINS
Number of bins.
static const uint32_t N_MEASUREMENTS
Number of measurements.
The random number generators Test Suite.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Smart pointer class similar to boost::intrusive_ptr.
static void SetSeed(uint32_t seed)
Set the seed.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
void FillHistoRangeUniformly(double *array, uint32_t n, double start, double end)
Fill an array with increasing values, in the [start, end] range.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static RngTestSuite g_rngTestSuite
Static variable for test initialization.