6#include "ns3/random-variable-stream.h"
7#include "ns3/rng-seed-manager.h"
11#include <gsl/gsl_cdf.h>
12#include <gsl/gsl_histogram.h>
40 double increment = (end - start) / (n - 1.);
76 void DoRun()
override;
80 :
TestCase(
"Uniform Random Number Generator")
91 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
92 gsl_histogram_set_ranges_uniform(h, 0., 1.);
96 gsl_histogram_increment(h,
u->GetValue());
105 tmp[i] = gsl_histogram_get(h, i);
111 gsl_histogram_free(h);
113 double chiSquared = 0;
117 chiSquared += tmp[i];
129 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
169 void DoRun()
override;
173 :
TestCase(
"Normal Random Number Generator")
184 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
188 range[0] = -std::numeric_limits<double>::max();
189 range[
N_BINS] = std::numeric_limits<double>::max();
191 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
199 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
205 gsl_histogram_increment(h, n->GetValue());
212 tmp[i] = gsl_histogram_get(h, i);
213 tmp[i] -= expected[i];
215 tmp[i] /= expected[i];
218 gsl_histogram_free(h);
220 double chiSquared = 0;
224 chiSquared += tmp[i];
236 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
276 void DoRun()
override;
280 :
TestCase(
"Exponential Random Number Generator")
291 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
295 range[
N_BINS] = std::numeric_limits<double>::max();
297 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
305 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
311 gsl_histogram_increment(h, e->GetValue());
318 tmp[i] = gsl_histogram_get(h, i);
319 tmp[i] -= expected[i];
321 tmp[i] /= expected[i];
324 gsl_histogram_free(h);
326 double chiSquared = 0;
330 chiSquared += tmp[i];
342 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
382 void DoRun()
override;
386 :
TestCase(
"Pareto Random Number Generator")
397 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
401 range[
N_BINS] = std::numeric_limits<double>::max();
403 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
408 double b = 0.33333333;
414 expected[i] = gsl_cdf_pareto_P(range[i + 1], a, b) - gsl_cdf_pareto_P(range[i], a, b);
420 gsl_histogram_increment(h, p->GetValue());
427 tmp[i] = gsl_histogram_get(h, i);
428 tmp[i] -= expected[i];
430 tmp[i] /= expected[i];
433 gsl_histogram_free(h);
435 double chiSquared = 0;
439 chiSquared += tmp[i];
451 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.