24 #include "ns3/average.h"
28 const double TOLERANCE = 1e-14;
41 virtual void DoRun (
void);
44 OneIntegerAverageTestCase::OneIntegerAverageTestCase ()
45 :
TestCase (
"Average Object Test using One Integer")
50 OneIntegerAverageTestCase::~OneIntegerAverageTestCase ()
72 for (
long i = 0; i < count; i++)
74 value = multiple * (i + 1);
79 sqrSum += value * value;
84 max = multiple * count;
92 variance = (count * sqrSum - sum * sum) / (count * (count - 1));
94 stddev = std::sqrt (variance);
97 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Count (), count, TOLERANCE,
"Count value wrong");
98 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Min (), min, TOLERANCE,
"Min value wrong");
99 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Max (), max, TOLERANCE,
"Max value wrong");
100 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Mean (), mean, TOLERANCE,
"Mean value wrong");
101 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Stddev (), stddev, TOLERANCE,
"Stddev value wrong");
102 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Var (), variance, TOLERANCE,
"Variance value wrong");
117 virtual void DoRun (
void);
120 FiveIntegersAverageTestCase::FiveIntegersAverageTestCase ()
121 :
TestCase (
"Average Object Test using Five Integers")
126 FiveIntegersAverageTestCase::~FiveIntegersAverageTestCase ()
148 for (
long i = 0; i < count; i++)
150 value = multiple * (i + 1);
152 calculator.
Update (value);
155 sqrSum += value * value;
160 max = multiple * count;
168 variance = (count * sqrSum - sum * sum) / (count * (count - 1));
170 stddev = std::sqrt (variance);
173 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Count (), count, TOLERANCE,
"Count value wrong");
174 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Min (), min, TOLERANCE,
"Min value wrong");
175 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Max (), max, TOLERANCE,
"Max value wrong");
176 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Mean (), mean, TOLERANCE,
"Mean value wrong");
177 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Stddev (), stddev, TOLERANCE,
"Stddev value wrong");
178 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Var (), variance, TOLERANCE,
"Variance value wrong");
193 virtual void DoRun (
void);
196 FiveDoublesAverageTestCase::FiveDoublesAverageTestCase ()
197 :
TestCase (
"Average Object Test using Five Double Values")
202 FiveDoublesAverageTestCase::~FiveDoublesAverageTestCase ()
222 double multiple = 3.14;
224 for (
long i = 0; i < count; i++)
226 value = multiple * (i + 1);
228 calculator.
Update (value);
231 sqrSum += value * value;
236 max = multiple * count;
244 variance = (count * sqrSum - sum * sum) / (count * (count - 1));
246 stddev = std::sqrt (variance);
249 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Count (), count, TOLERANCE,
"Count value wrong");
250 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Min (), min, TOLERANCE,
"Min value wrong");
251 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Max (), max, TOLERANCE,
"Max value wrong");
252 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Mean (), mean, TOLERANCE,
"Mean value wrong");
253 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Stddev (), stddev, TOLERANCE,
"Stddev value wrong");
254 NS_TEST_ASSERT_MSG_EQ_TOL (calculator.
Var (), variance, TOLERANCE,
"Variance value wrong");
264 AverageTestSuite::AverageTestSuite ()
double Stddev() const
Standard deviation.
double Mean() const
Estimate of mean, alias to Avg.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
virtual void DoRun(void)
Implementation to actually run this test case.
uint32_t Count() const
Sample size.
double Var() const
Unbiased estimate of variance.
void Update(T const &x)
Add new sample.