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"
26#include <gsl/gsl_cdf.h>
27#include <gsl/gsl_histogram.h>
28#include <gsl/gsl_randist.h>
29#include <gsl/gsl_sf_zeta.h>
87 bool underflow =
true,
88 bool overflow =
true)
const
91 std::size_t nBins = gsl_histogram_bins(h);
92 double increment = (end - start) / (nBins - 1.);
95 std::vector<double> range(nBins + 1);
104 range[0] = -std::numeric_limits<double>::max();
108 range[nBins] = std::numeric_limits<double>::max();
111 gsl_histogram_set_ranges(h, range.data(), nBins + 1);
126 double value = rng->GetValue();
145 const auto value = rng->GetValue();
146 sum += std::pow(value - average, 2);
149 return valueVariance;
168 template <
typename RNG>
210 const std::vector<double>& expected,
215 "Histogram and expected vector have different sizes.");
220 double value = rng->GetValue();
221 gsl_histogram_increment(h, value);
225 double chiSquared = 0;
226 std::size_t nBins = gsl_histogram_bins(h);
227 for (std::size_t i = 0; i < nBins; ++i)
229 double hbin = gsl_histogram_get(h, i);
230 double tmp = hbin - expected[i];
287 for (std::size_t i = 0; i < nRuns; ++i)
289 auto rng = generator->
Create();
335 seed =
static_cast<uint32_t>(time(
nullptr));
338 "Special run number value of zero; seeding with time of day: " << seed);
373 void DoRun()
override;
377 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
384 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
388 gsl_histogram_set_ranges_uniform(h, 0., 1.);
392 double chiSquared =
ChiSquared(h, expected, rng);
393 gsl_histogram_free(h);
403 double confidence = 0.99;
404 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
406 <<
" bins is " << maxStatistic);
408 double result = maxStatistic;
415 if (
result < maxStatistic)
439 value =
x->GetValue();
445 static const uint32_t UNIFORM_INTEGER_MIN{0};
446 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
449 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
452 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
456 for (
int i = 0; i < 20; i++)
458 intValue +=
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
464 for (
int i = 0; i < 20; i++)
466 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
467 if (intValue == UNIFORM_INTEGER_MAX)
475 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
476 uint32_t intValue2 =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
495 void DoRun()
override;
499 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
506 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
510 gsl_histogram_set_ranges_uniform(h, 0., 1.);
514 double chiSquared =
ChiSquared(h, expected, rng);
515 gsl_histogram_free(h);
527 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
549 value =
x->GetValue();
567 void DoRun()
override;
574 :
TestCaseBase(
"Constant Random Variable Stream Generator")
590 c->SetAttribute(
"Constant",
DoubleValue(constant));
596 constant = c->GetValue();
602 "Constant value changed in loop");
618 void DoRun()
override;
625 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
643 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
649 value = s->GetValue();
651 value = s->GetValue();
653 value = s->GetValue();
655 value = s->GetValue();
657 value = s->GetValue();
659 value = s->GetValue();
678 void DoRun()
override;
685 :
TestCaseBase(
"Normal Random Variable Stream Generator")
692 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
695 std::vector<double> expected(
N_BINS);
702 for (std::size_t i = 0; i <
N_BINS; ++i)
704 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
708 double chiSquared =
ChiSquared(h, expected, rng);
709 gsl_histogram_free(h);
720 auto rng = generator.Create();
723 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
727 double variance = 2.0;
739 double expectedMean = mean;
746 "Wrong mean value.");
749 x->SetStdDev(sqrt(variance));
763 "Wrong mean value.");
781 void DoRun()
override;
788 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
795 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
798 std::vector<double> expected(
N_BINS);
805 for (std::size_t i = 0; i <
N_BINS; ++i)
807 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
811 double chiSquared =
ChiSquared(h, expected, rng);
813 gsl_histogram_free(h);
825 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
829 double variance = 2.0;
844 double expectedMean = mean;
851 "Wrong mean value.");
869 void DoRun()
override;
876 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
883 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
886 std::vector<double> expected(
N_BINS);
892 for (std::size_t i = 0; i <
N_BINS; ++i)
894 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
898 double chiSquared =
ChiSquared(h, expected, rng);
900 gsl_histogram_free(h);
912 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
925 double expectedMean = mean;
932 "Wrong mean value.");
950 void DoRun()
override;
957 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
964 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
967 std::vector<double> expected(
N_BINS);
973 for (std::size_t i = 0; i <
N_BINS; ++i)
975 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
979 double chiSquared =
ChiSquared(h, expected, rng);
981 gsl_histogram_free(h);
993 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1009 double expectedMean = mean;
1016 "Wrong mean value.");
1034 void DoRun()
override;
1044 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1051 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1054 std::vector<double> expected(
N_BINS);
1059 for (std::size_t i = 0; i <
N_BINS; ++i)
1062 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1066 double chiSquared =
ChiSquared(h, expected, rng);
1068 gsl_histogram_free(h);
1080 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1103 double expectedMean = (shape * scale) / (shape - 1.0);
1109 "Wrong mean value.");
1127 void DoRun()
override;
1137 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1144 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1147 std::vector<double> expected(
N_BINS);
1152 for (std::size_t i = 0; i <
N_BINS; ++i)
1155 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1159 double chiSquared =
ChiSquared(h, expected, rng);
1161 gsl_histogram_free(h);
1173 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1200 double expectedMean = (shape * scale) / (shape - 1.0);
1206 "Wrong mean value.");
1224 void DoRun()
override;
1234 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1241 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1244 std::vector<double> expected(
N_BINS);
1252 for (std::size_t i = 0; i <
N_BINS; ++i)
1254 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1259 double chiSquared =
ChiSquared(h, expected, rng);
1261 gsl_histogram_free(h);
1273 const auto maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1276 const auto scale = 5.0;
1277 const auto shape = 1.0;
1285 const auto measuredMean =
Average(
x);
1309 const auto expectedMean = scale;
1312 const auto valueMean =
x->GetMean();
1319 "Wrong measured mean value.");
1337 void DoRun()
override;
1347 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1354 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1357 std::vector<double> expected(
N_BINS);
1365 for (std::size_t i = 0; i <
N_BINS; ++i)
1367 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1371 double chiSquared =
ChiSquared(h, expected, rng);
1373 gsl_histogram_free(h);
1385 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1424 double expectedMean = scale;
1430 "Wrong mean value.");
1448 void DoRun()
override;
1458 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1465 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1468 std::vector<double> expected(
N_BINS);
1476 for (std::size_t i = 0; i <
N_BINS; ++i)
1479 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1483 double chiSquared =
ChiSquared(h, expected, rng);
1485 gsl_histogram_free(h);
1497 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1519 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1532 "Wrong mean value.");
1550 void DoRun()
override;
1560 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1567 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1570 std::vector<double> expected(
N_BINS);
1578 for (std::size_t i = 0; i <
N_BINS; ++i)
1581 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1585 double chiSquared =
ChiSquared(h, expected, rng);
1587 gsl_histogram_free(h);
1599 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1623 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1636 "Wrong mean value.");
1654 void DoRun()
override;
1664 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1671 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1674 std::vector<double> expected(
N_BINS);
1682 for (std::size_t i = 0; i <
N_BINS; ++i)
1685 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1689 double chiSquared =
ChiSquared(h, expected, rng);
1691 gsl_histogram_free(h);
1703 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1722 double expectedMean = alpha * beta;
1728 "Wrong mean value.");
1746 void DoRun()
override;
1756 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1763 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1766 std::vector<double> expected(
N_BINS);
1774 for (std::size_t i = 0; i <
N_BINS; ++i)
1777 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1781 double chiSquared =
ChiSquared(h, expected, rng);
1783 gsl_histogram_free(h);
1795 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1818 double expectedMean = alpha * beta;
1824 "Wrong mean value.");
1842 void DoRun()
override;
1852 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1859 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1862 std::vector<double> expected(
N_BINS);
1868 double lambda = 1.0;
1873 for (std::size_t i = 0; i <
N_BINS; ++i)
1876 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1880 double chiSquared =
ChiSquared(h, expected, rng);
1882 gsl_histogram_free(h);
1894 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1898 double lambda = 2.0;
1913 double expectedMean = k * lambda;
1919 "Wrong mean value.");
1937 void DoRun()
override;
1947 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1954 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1957 std::vector<double> expected(
N_BINS);
1963 double lambda = 1.0;
1968 for (std::size_t i = 0; i <
N_BINS; ++i)
1971 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1975 double chiSquared =
ChiSquared(h, expected, rng);
1977 gsl_histogram_free(h);
1989 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1993 double lambda = 2.0;
2012 double expectedMean = k * lambda;
2018 "Wrong mean value.");
2033 void DoRun()
override;
2043 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2092 double expectedMean = 1.0;
2098 "Wrong mean value.");
2113 void DoRun()
override;
2123 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2175 double expectedMean = 1.0;
2181 "Wrong mean value.");
2196 void DoRun()
override;
2206 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2237 double expectedMean =
2238 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2244 "Wrong mean value.");
2259 void DoRun()
override;
2269 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2303 double expectedMean =
2304 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2310 "Wrong mean value.");
2325 void DoRun()
override;
2332 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2348 double array1[] = {4, 4, 7, 7, 10, 10};
2349 std::size_t count1 = 6;
2350 s->SetValueArray(array1, count1);
2355 value = s->GetValue();
2357 value = s->GetValue();
2359 value = s->GetValue();
2361 value = s->GetValue();
2363 value = s->GetValue();
2365 value = s->GetValue();
2372 double array2[] = {1000, 2000, 3000, 4000};
2373 std::size_t count2 = 4;
2374 s->SetValueArray(array2, count2);
2377 value = s->GetValue();
2379 value = s->GetValue();
2381 value = s->GetValue();
2383 value = s->GetValue();
2385 value = s->GetValue();
2400 void DoRun()
override;
2410 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2422 x->SetInterpolate(
false);
2430 double value =
x->GetValue();
2433 "Incorrect value returned, expected only 5 or 10.");
2449 double expectedMean = 8.75;
2453 "Wrong mean value.");
2456 x->SetInterpolate(
true);
2471 expectedMean = 6.25;
2477 "Wrong mean value.");
2481 y->SetInterpolate(
false);
2500 void DoRun()
override;
2510 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2522 x->SetInterpolate(
false);
2533 double value =
x->GetValue();
2536 "Incorrect value returned, expected only 5 or 10.");
2543 double expectedMean = 8.75;
2547 "Wrong mean value.");
2550 x->SetInterpolate(
true);
2558 expectedMean = 6.25;
2564 "Wrong mean value.");
2579 void DoRun()
override;
2583 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2594 double v1 = n->GetValue(-10, 1, 10);
2595 double v2 = n->GetValue(10, 1, 10);
2616 void DoRun()
override;
2623 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2630 gsl_histogram* h = gsl_histogram_alloc(2);
2636 double chiSquared =
ChiSquared(h, expected, rng);
2638 gsl_histogram_free(h);
2650 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2653 double probability = 0.5;
2657 x->SetAttribute(
"Probability",
DoubleValue(probability));
2660 double mean = probability;
2662 double expectedMean = mean;
2669 "Wrong mean value.");
2687 void DoRun()
override;
2694 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2701 gsl_histogram* h = gsl_histogram_alloc(2);
2707 double chiSquared =
ChiSquared(h, expected, rng);
2709 gsl_histogram_free(h);
2721 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2724 double probability = 0.5;
2728 x->SetAttribute(
"Probability",
DoubleValue(probability));
2734 double mean = probability;
2736 double expectedMean = mean;
2743 "Wrong mean value.");
2761 void DoRun()
override;
2768 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2776 double probability = 0.5;
2778 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2781 std::vector<double> expected(trials + 1);
2782 for (std::size_t i = 0; i < trials + 1; ++i)
2784 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2787 double chiSquared =
ChiSquared(h, expected, rng);
2789 gsl_histogram_free(h);
2800 double probability = 0.5;
2804 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2810 x->SetAttribute(
"Probability",
DoubleValue(probability));
2813 double mean = trials * probability;
2815 double expectedMean = mean;
2822 "Wrong mean value.");
2840 void DoRun()
override;
2847 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2855 double probability = 0.5;
2857 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2860 std::vector<double> expected(trials + 1);
2861 for (std::size_t i = 0; i < trials + 1; ++i)
2863 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2866 double chiSquared =
ChiSquared(h, expected, rng);
2868 gsl_histogram_free(h);
2879 double probability = 0.5;
2883 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2889 x->SetAttribute(
"Probability",
DoubleValue(probability));
2895 double mean = trials * probability;
2897 double expectedMean = mean;
2904 "Wrong mean value.");
2921 void DoRun()
override;
2925 :
TestCase(
"Check correct operation of the Shuffle function")
2939 std::vector<uint8_t> vec{};
2941 Shuffle(vec.begin(), vec.end(), rv);
2948 Shuffle(vec.begin(), vec.end(), rv);
2955 Shuffle(vec.begin(), vec.end(), rv);
2965 Shuffle(vec.begin(), vec.end(), rv);
2969 "Expected vector {4, 1, 9, 3, 2, 7}");
2982 void DoRun()
override;
2992 :
TestCaseBase(
"Laplacian Random Variable Stream Generator")
3004 double bound = 20.0;
3015 auto valueVariance =
Variance(x1, valueMean);
3018 const auto expectedMean = mu;
3026 "Wrong variance value.");
3041 const auto lowerBound = mu - bound;
3042 const auto upperBound = mu + bound;
3045 const auto value = x2->GetValue();
3048 "Value not in expected boundaries.");
3062 void DoRun()
override;
3072 :
TestCaseBase(
"Largest Extreme Value Random Variable Stream Generator")
3094 auto valueVariance =
Variance(
x, valueMean);
3105 "Wrong variance value.");
3121 :
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
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