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>
42 double increment = (end - start) / (n - 1.);
78 void DoRun()
override;
82 :
TestCase(
"Uniform Random Number Generator")
93 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
94 gsl_histogram_set_ranges_uniform(h, 0., 1.);
98 gsl_histogram_increment(h,
u->GetValue());
107 tmp[i] = gsl_histogram_get(h, i);
113 gsl_histogram_free(h);
115 double chiSquared = 0;
119 chiSquared += tmp[i];
131 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
171 void DoRun()
override;
175 :
TestCase(
"Normal Random Number Generator")
186 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
190 range[0] = -std::numeric_limits<double>::max();
191 range[
N_BINS] = std::numeric_limits<double>::max();
193 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
201 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
207 gsl_histogram_increment(h, n->GetValue());
214 tmp[i] = gsl_histogram_get(h, i);
215 tmp[i] -= expected[i];
217 tmp[i] /= expected[i];
220 gsl_histogram_free(h);
222 double chiSquared = 0;
226 chiSquared += tmp[i];
238 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
278 void DoRun()
override;
282 :
TestCase(
"Exponential Random Number Generator")
293 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
297 range[
N_BINS] = std::numeric_limits<double>::max();
299 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
307 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
313 gsl_histogram_increment(h, e->GetValue());
320 tmp[i] = gsl_histogram_get(h, i);
321 tmp[i] -= expected[i];
323 tmp[i] /= expected[i];
326 gsl_histogram_free(h);
328 double chiSquared = 0;
332 chiSquared += tmp[i];
344 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
384 void DoRun()
override;
388 :
TestCase(
"Pareto Random Number Generator")
399 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
403 range[
N_BINS] = std::numeric_limits<double>::max();
405 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
410 double b = 0.33333333;
416 expected[i] = gsl_cdf_pareto_P(range[i + 1], a, b) - gsl_cdf_pareto_P(range[i], a, b);
422 gsl_histogram_increment(h, p->GetValue());
429 tmp[i] = gsl_histogram_get(h, i);
430 tmp[i] -= expected[i];
432 tmp[i] /= expected[i];
435 gsl_histogram_free(h);
437 double chiSquared = 0;
441 chiSquared += tmp[i];
453 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.
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new 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.