12#include "ns3/boolean.h"
13#include "ns3/double.h"
14#include "ns3/integer.h"
16#include "ns3/random-variable-stream.h"
17#include "ns3/rng-seed-manager.h"
18#include "ns3/shuffle.h"
19#include "ns3/string.h"
21#include "ns3/uinteger.h"
25#include <gsl/gsl_cdf.h>
26#include <gsl/gsl_histogram.h>
27#include <gsl/gsl_randist.h>
28#include <gsl/gsl_sf_zeta.h>
86 bool underflow =
true,
87 bool overflow =
true)
const
90 std::size_t nBins = gsl_histogram_bins(h);
91 double increment = (end - start) / (nBins - 1.);
94 std::vector<double> range(nBins + 1);
103 range[0] = -std::numeric_limits<double>::max();
107 range[nBins] = std::numeric_limits<double>::max();
110 gsl_histogram_set_ranges(h, range.data(), nBins + 1);
125 double value = rng->GetValue();
144 const auto value = rng->GetValue();
145 sum += std::pow(value - average, 2);
148 return valueVariance;
167 template <
typename RNG>
209 const std::vector<double>& expected,
214 "Histogram and expected vector have different sizes.");
219 double value = rng->GetValue();
220 gsl_histogram_increment(h, value);
224 double chiSquared = 0;
225 std::size_t nBins = gsl_histogram_bins(h);
226 for (std::size_t i = 0; i < nBins; ++i)
228 double hbin = gsl_histogram_get(h, i);
229 double tmp = hbin - expected[i];
286 for (std::size_t i = 0; i < nRuns; ++i)
288 auto rng = generator->
Create();
334 seed =
static_cast<uint32_t>(time(
nullptr));
337 "Special run number value of zero; seeding with time of day: " << seed);
372 void DoRun()
override;
376 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
383 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
387 gsl_histogram_set_ranges_uniform(h, 0., 1.);
391 double chiSquared =
ChiSquared(h, expected, rng);
392 gsl_histogram_free(h);
402 double confidence = 0.99;
403 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
405 <<
" bins is " << maxStatistic);
407 double result = maxStatistic;
414 if (
result < maxStatistic)
438 value =
x->GetValue();
444 static const uint32_t UNIFORM_INTEGER_MIN{0};
445 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
448 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
451 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
455 for (
int i = 0; i < 20; i++)
457 intValue +=
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
463 for (
int i = 0; i < 20; i++)
465 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
466 if (intValue == UNIFORM_INTEGER_MAX)
474 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
475 uint32_t intValue2 =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
494 void DoRun()
override;
498 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
505 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
509 gsl_histogram_set_ranges_uniform(h, 0., 1.);
513 double chiSquared =
ChiSquared(h, expected, rng);
514 gsl_histogram_free(h);
526 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
548 value =
x->GetValue();
566 void DoRun()
override;
573 :
TestCaseBase(
"Constant Random Variable Stream Generator")
589 c->SetAttribute(
"Constant",
DoubleValue(constant));
595 constant = c->GetValue();
601 "Constant value changed in loop");
617 void DoRun()
override;
624 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
642 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
648 value = s->GetValue();
650 value = s->GetValue();
652 value = s->GetValue();
654 value = s->GetValue();
656 value = s->GetValue();
658 value = s->GetValue();
677 void DoRun()
override;
684 :
TestCaseBase(
"Normal Random Variable Stream Generator")
691 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
694 std::vector<double> expected(
N_BINS);
701 for (std::size_t i = 0; i <
N_BINS; ++i)
703 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
707 double chiSquared =
ChiSquared(h, expected, rng);
708 gsl_histogram_free(h);
719 auto rng = generator.Create();
722 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
726 double variance = 2.0;
738 double expectedMean = mean;
745 "Wrong mean value.");
748 x->SetStdDev(sqrt(variance));
762 "Wrong mean value.");
780 void DoRun()
override;
787 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
794 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
797 std::vector<double> expected(
N_BINS);
804 for (std::size_t i = 0; i <
N_BINS; ++i)
806 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
810 double chiSquared =
ChiSquared(h, expected, rng);
812 gsl_histogram_free(h);
824 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
828 double variance = 2.0;
843 double expectedMean = mean;
850 "Wrong mean value.");
868 void DoRun()
override;
875 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
882 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
885 std::vector<double> expected(
N_BINS);
891 for (std::size_t i = 0; i <
N_BINS; ++i)
893 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
897 double chiSquared =
ChiSquared(h, expected, rng);
899 gsl_histogram_free(h);
911 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
924 double expectedMean = mean;
931 "Wrong mean value.");
949 void DoRun()
override;
956 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
963 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
966 std::vector<double> expected(
N_BINS);
972 for (std::size_t i = 0; i <
N_BINS; ++i)
974 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
978 double chiSquared =
ChiSquared(h, expected, rng);
980 gsl_histogram_free(h);
992 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1008 double expectedMean = mean;
1015 "Wrong mean value.");
1033 void DoRun()
override;
1043 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1050 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1053 std::vector<double> expected(
N_BINS);
1058 for (std::size_t i = 0; i <
N_BINS; ++i)
1061 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1065 double chiSquared =
ChiSquared(h, expected, rng);
1067 gsl_histogram_free(h);
1079 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1102 double expectedMean = (shape * scale) / (shape - 1.0);
1108 "Wrong mean value.");
1126 void DoRun()
override;
1136 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1143 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1146 std::vector<double> expected(
N_BINS);
1151 for (std::size_t i = 0; i <
N_BINS; ++i)
1154 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1158 double chiSquared =
ChiSquared(h, expected, rng);
1160 gsl_histogram_free(h);
1172 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1199 double expectedMean = (shape * scale) / (shape - 1.0);
1205 "Wrong mean value.");
1223 void DoRun()
override;
1233 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1240 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1243 std::vector<double> expected(
N_BINS);
1251 for (std::size_t i = 0; i <
N_BINS; ++i)
1253 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1258 double chiSquared =
ChiSquared(h, expected, rng);
1260 gsl_histogram_free(h);
1272 const auto maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1275 const auto scale = 5.0;
1276 const auto shape = 1.0;
1284 const auto measuredMean =
Average(
x);
1308 const auto expectedMean = scale;
1311 const auto valueMean =
x->GetMean();
1318 "Wrong measured mean value.");
1336 void DoRun()
override;
1346 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1353 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1356 std::vector<double> expected(
N_BINS);
1364 for (std::size_t i = 0; i <
N_BINS; ++i)
1366 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1370 double chiSquared =
ChiSquared(h, expected, rng);
1372 gsl_histogram_free(h);
1384 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1423 double expectedMean = scale;
1429 "Wrong mean value.");
1447 void DoRun()
override;
1457 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1464 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1467 std::vector<double> expected(
N_BINS);
1475 for (std::size_t i = 0; i <
N_BINS; ++i)
1478 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1482 double chiSquared =
ChiSquared(h, expected, rng);
1484 gsl_histogram_free(h);
1496 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1518 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1531 "Wrong mean value.");
1549 void DoRun()
override;
1559 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1566 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1569 std::vector<double> expected(
N_BINS);
1577 for (std::size_t i = 0; i <
N_BINS; ++i)
1580 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1584 double chiSquared =
ChiSquared(h, expected, rng);
1586 gsl_histogram_free(h);
1598 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1622 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1635 "Wrong mean value.");
1653 void DoRun()
override;
1663 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1670 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1673 std::vector<double> expected(
N_BINS);
1681 for (std::size_t i = 0; i <
N_BINS; ++i)
1684 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1688 double chiSquared =
ChiSquared(h, expected, rng);
1690 gsl_histogram_free(h);
1702 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1721 double expectedMean = alpha * beta;
1727 "Wrong mean value.");
1745 void DoRun()
override;
1755 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1762 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1765 std::vector<double> expected(
N_BINS);
1773 for (std::size_t i = 0; i <
N_BINS; ++i)
1776 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1780 double chiSquared =
ChiSquared(h, expected, rng);
1782 gsl_histogram_free(h);
1794 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1817 double expectedMean = alpha * beta;
1823 "Wrong mean value.");
1841 void DoRun()
override;
1851 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1858 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1861 std::vector<double> expected(
N_BINS);
1867 double lambda = 1.0;
1872 for (std::size_t i = 0; i <
N_BINS; ++i)
1875 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1879 double chiSquared =
ChiSquared(h, expected, rng);
1881 gsl_histogram_free(h);
1893 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1897 double lambda = 2.0;
1912 double expectedMean = k * lambda;
1918 "Wrong mean value.");
1936 void DoRun()
override;
1946 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1953 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1956 std::vector<double> expected(
N_BINS);
1962 double lambda = 1.0;
1967 for (std::size_t i = 0; i <
N_BINS; ++i)
1970 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1974 double chiSquared =
ChiSquared(h, expected, rng);
1976 gsl_histogram_free(h);
1988 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1992 double lambda = 2.0;
2011 double expectedMean = k * lambda;
2017 "Wrong mean value.");
2032 void DoRun()
override;
2042 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2091 double expectedMean = 1.0;
2097 "Wrong mean value.");
2112 void DoRun()
override;
2122 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2174 double expectedMean = 1.0;
2180 "Wrong mean value.");
2195 void DoRun()
override;
2205 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2236 double expectedMean =
2237 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2243 "Wrong mean value.");
2258 void DoRun()
override;
2268 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2302 double expectedMean =
2303 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2309 "Wrong mean value.");
2324 void DoRun()
override;
2331 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2347 double array1[] = {4, 4, 7, 7, 10, 10};
2348 std::size_t count1 = 6;
2349 s->SetValueArray(array1, count1);
2354 value = s->GetValue();
2356 value = s->GetValue();
2358 value = s->GetValue();
2360 value = s->GetValue();
2362 value = s->GetValue();
2364 value = s->GetValue();
2371 double array2[] = {1000, 2000, 3000, 4000};
2372 std::size_t count2 = 4;
2373 s->SetValueArray(array2, count2);
2376 value = s->GetValue();
2378 value = s->GetValue();
2380 value = s->GetValue();
2382 value = s->GetValue();
2384 value = s->GetValue();
2399 void DoRun()
override;
2409 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2421 x->SetInterpolate(
false);
2429 double value =
x->GetValue();
2432 "Incorrect value returned, expected only 5 or 10.");
2448 double expectedMean = 8.75;
2452 "Wrong mean value.");
2455 x->SetInterpolate(
true);
2470 expectedMean = 6.25;
2476 "Wrong mean value.");
2480 y->SetInterpolate(
false);
2499 void DoRun()
override;
2509 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2521 x->SetInterpolate(
false);
2532 double value =
x->GetValue();
2535 "Incorrect value returned, expected only 5 or 10.");
2542 double expectedMean = 8.75;
2546 "Wrong mean value.");
2549 x->SetInterpolate(
true);
2557 expectedMean = 6.25;
2563 "Wrong mean value.");
2578 void DoRun()
override;
2582 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2593 double v1 = n->GetValue(-10, 1, 10);
2594 double v2 = n->GetValue(10, 1, 10);
2615 void DoRun()
override;
2622 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2629 gsl_histogram* h = gsl_histogram_alloc(2);
2635 double chiSquared =
ChiSquared(h, expected, rng);
2637 gsl_histogram_free(h);
2649 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2652 double probability = 0.5;
2656 x->SetAttribute(
"Probability",
DoubleValue(probability));
2659 double mean = probability;
2661 double expectedMean = mean;
2668 "Wrong mean value.");
2686 void DoRun()
override;
2693 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2700 gsl_histogram* h = gsl_histogram_alloc(2);
2706 double chiSquared =
ChiSquared(h, expected, rng);
2708 gsl_histogram_free(h);
2720 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2723 double probability = 0.5;
2727 x->SetAttribute(
"Probability",
DoubleValue(probability));
2733 double mean = probability;
2735 double expectedMean = mean;
2742 "Wrong mean value.");
2760 void DoRun()
override;
2767 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2775 double probability = 0.5;
2777 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2780 std::vector<double> expected(trials + 1);
2781 for (std::size_t i = 0; i < trials + 1; ++i)
2783 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2786 double chiSquared =
ChiSquared(h, expected, rng);
2788 gsl_histogram_free(h);
2799 double probability = 0.5;
2803 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2809 x->SetAttribute(
"Probability",
DoubleValue(probability));
2812 double mean = trials * probability;
2814 double expectedMean = mean;
2821 "Wrong mean value.");
2839 void DoRun()
override;
2846 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2854 double probability = 0.5;
2856 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2859 std::vector<double> expected(trials + 1);
2860 for (std::size_t i = 0; i < trials + 1; ++i)
2862 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2865 double chiSquared =
ChiSquared(h, expected, rng);
2867 gsl_histogram_free(h);
2878 double probability = 0.5;
2882 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2888 x->SetAttribute(
"Probability",
DoubleValue(probability));
2894 double mean = trials * probability;
2896 double expectedMean = mean;
2903 "Wrong mean value.");
2920 void DoRun()
override;
2924 :
TestCase(
"Check correct operation of the Shuffle function")
2938 std::vector<uint8_t> vec{};
2940 Shuffle(vec.begin(), vec.end(), rv);
2947 Shuffle(vec.begin(), vec.end(), rv);
2954 Shuffle(vec.begin(), vec.end(), rv);
2964 Shuffle(vec.begin(), vec.end(), rv);
2968 "Expected vector {4, 1, 9, 3, 2, 7}");
2981 void DoRun()
override;
2991 :
TestCaseBase(
"Laplacian Random Variable Stream Generator")
3003 double bound = 20.0;
3014 auto valueVariance =
Variance(x1, valueMean);
3017 const auto expectedMean = mu;
3025 "Wrong variance value.");
3040 const auto lowerBound = mu - bound;
3041 const auto upperBound = mu + bound;
3044 const auto value = x2->GetValue();
3047 "Value not in expected boundaries.");
3061 void DoRun()
override;
3071 :
TestCaseBase(
"Largest Extreme Value Random Variable Stream Generator")
3093 auto valueVariance =
Variance(
x, valueMean);
3104 "Wrong variance value.");
3120 :
TestSuite(
"random-variable-stream-generators",
Type::UNIT)
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold a signed integer type.
double GetVariance() const
Returns the variance value for the laplacian distribution returned by this RNG stream.
double GetMean() const
Returns the mean value for the Largest Extreme Value distribution returned by this RNG stream.
double GetVariance() const
Returns the variance value for the Largest Extreme Value distribution returned by this RNG stream.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Hold variables of type string.
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.
Test case for antithetic bernoulli distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BernoulliAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for bernoulli distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BinomialAntitheticTestCase()
Test case for binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for constant random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
Test case for deterministic random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
Test case for antithetic empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
EmpiricalAntitheticTestCase()
Test case for empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Erlang distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ErlangAntitheticTestCase()
Test case for Erlang distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ExponentialAntitheticTestCase()
Test case for exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
GammaAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
Test case for gamma distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for laplacian distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for largest extreme value distribution random variable stream generator.
LargestExtremeValueTestCase()
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
LogNormalAntitheticTestCase()
Test case for log-normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic normal distribution random variable stream generator.
NormalAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for caching of Normal RV parameters (see issue #302).
void DoRun() override
Implementation to actually run this TestCase.
Test case for normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
Test case for antithetic Pareto distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ParetoAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for Pareto distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
RandomVariableStream test suite, covering all random number variable stream generator types.
Test case for sequential random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
Test the Shuffle function.
void DoRun() override
Implementation to actually run this TestCase.
A factory base class to create new instances of a random variable.
virtual Ptr< RandomVariableStream > Create() const =0
Create a new instance of a random variable stream.
Factory class to create new instances of a particular random variable stream.
Ptr< RandomVariableStream > Create() const override
Create a new instance of a random variable stream.
bool m_anti
Whether to create antithetic random variable streams.
RngGenerator(bool anti=false)
Constructor.
double ChiSquared(gsl_histogram *h, const std::vector< double > &expected, Ptr< RandomVariableStream > rng) const
Compute the chi squared value of a sampled distribution compared to the expected distribution.
static const uint32_t N_MEASUREMENTS
Number of samples to draw when populating the distributions.
void SetTestSuiteSeed()
Set the seed used for this test suite.
double ChiSquaredsAverage(const RngGeneratorBase *generator, std::size_t nRuns) const
Average the chi squared value over some number of runs, each run with a new instance of the random nu...
std::vector< double > UniformHistogramBins(gsl_histogram *h, double start, double end, bool underflow=true, bool overflow=true) const
Configure a GSL histogram with uniform bins, with optional under/over-flow bins.
virtual double ChiSquaredTest(Ptr< RandomVariableStream > rng) const
Compute the chi square value from a random variable.
static const uint32_t N_BINS
Number of bins for sampling the distributions.
double Variance(Ptr< RandomVariableStream > rng, double average) const
Compute the variance of a random variable.
bool m_seedSet
true if we've already set the seed the correctly.
TestCaseBase(std::string name)
Constructor.
static const uint32_t N_RUNS
Number of retry attempts to pass a chi-square test.
double Average(Ptr< RandomVariableStream > rng) const
Compute the average of a random variable.
Test case for antithetic Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
WeibullAntitheticTestCase()
Test case for Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic Zipf distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zipf distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
static RandomVariableSuite randomVariableSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Shuffle(RND_ACCESS_ITER first, RND_ACCESS_ITER last, Ptr< UniformRandomVariable > rv)
Shuffle the elements in the range first to last.
-ns3 Test suite for the ns3 wrapper script