27 #include "ns3/assert.h"
28 #include "ns3/integer.h"
29 #include "ns3/random-variable.h"
42 virtual void DoRun (
void);
46 :
TestCase (
"Check basic random number operation")
53 const double desiredMean = 1.0;
54 const double desiredStdDev = 1.0;
56 double tmp = std::log (1 + (desiredStdDev / desiredMean) * (desiredStdDev / desiredMean));
57 double sigma = std::sqrt (tmp);
58 double mu = std::log (desiredMean) - 0.5 * tmp;
65 std::vector<double> samples;
66 const int NSAMPLES = 10000;
73 for (
int n = NSAMPLES; n; --n)
75 double value = lognormal.
GetValue ();
77 samples.push_back (value);
79 double obtainedMean = sum / NSAMPLES;
86 for (std::vector<double>::iterator iter = samples.begin (); iter != samples.end (); iter++)
88 double tmp = (*iter - obtainedMean);
91 double obtainedStdDev = std::sqrt (sum / (NSAMPLES - 1));
92 NS_TEST_EXPECT_MSG_EQ_TOL (obtainedStdDev, desiredStdDev, 0.1,
"Got unexpected standard deviation from LogNormalVariable");
104 virtual void DoRun (
void);
108 :
TestCase (
"Check basic random number operation")
119 "Deserialize and Serialize \"Uniform:0.1:0.2\" mismatch");
124 "Deserialize and Serialize \"Normal:0.1:0.2\" mismatch");
129 "Deserialize and Serialize \"Normal:0.1:0.2:0.15\" mismatch");
139 :
TestSuite (
"basic-random-number", UNIT)
virtual ~RandomNumberSerializationTestCase()
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
hold objects of type ns3::RandomVariable
Log-normal Distributed random varLogNormalVariable defines a random variable with log-normal distribu...
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
RandomVariable Get(void) const
RandomNumberSerializationTestCase()
BasicRandomNumberTestSuite()
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
virtual ~BasicRandomNumberTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
double GetValue(void) const
Returns a random double from the underlying distribution.
BasicRandomNumberTestCase()
static BasicRandomNumberTestSuite BasicRandomNumberTestSuite
#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.