LEFT | RIGHT |
(no file at all) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
(...skipping 23 matching lines...) Expand all Loading... |
34 double increment = (end - start) / (n - 1.); | 34 double increment = (end - start) / (n - 1.); |
35 double d = start; | 35 double d = start; |
36 | 36 |
37 for (uint32_t i = 0; i < n; ++i) | 37 for (uint32_t i = 0; i < n; ++i) |
38 { | 38 { |
39 array[i] = d; | 39 array[i] = d; |
40 d += increment; | 40 d += increment; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 // =========================================================================== | 44 /** |
45 // Test case for uniform distribution random number generator | 45 * \ingroup core-test |
46 // =========================================================================== | 46 * \ingroup tests |
| 47 * |
| 48 * \brief Test case for uniform distribution random number generator |
| 49 */ |
47 class RngUniformTestCase : public TestCase | 50 class RngUniformTestCase : public TestCase |
48 { | 51 { |
49 public: | 52 public: |
50 static const uint32_t N_RUNS = 5; | 53 static const uint32_t N_RUNS = 5; ///< number of runs |
51 static const uint32_t N_BINS = 50; | 54 static const uint32_t N_BINS = 50; ///< number of bins |
52 static const uint32_t N_MEASUREMENTS = 1000000; | 55 static const uint32_t N_MEASUREMENTS = 1000000; ///< number of measurements |
53 | 56 |
54 RngUniformTestCase (); | 57 RngUniformTestCase (); |
55 virtual ~RngUniformTestCase (); | 58 virtual ~RngUniformTestCase (); |
56 | 59 |
| 60 /** |
| 61 * Chi squared test function |
| 62 * \param u The uniform random value |
| 63 * \returns the chi squared value |
| 64 */ |
57 double ChiSquaredTest (Ptr<UniformRandomVariable> u); | 65 double ChiSquaredTest (Ptr<UniformRandomVariable> u); |
58 | 66 |
59 private: | 67 private: |
60 virtual void DoRun (void); | 68 virtual void DoRun (void); |
61 }; | 69 }; |
62 | 70 |
63 RngUniformTestCase::RngUniformTestCase () | 71 RngUniformTestCase::RngUniformTestCase () |
64 : TestCase ("Uniform Random Number Generator") | 72 : TestCase ("Uniform Random Number Generator") |
65 { | 73 { |
66 } | 74 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 Ptr<UniformRandomVariable> u = CreateObject<UniformRandomVariable> (); | 125 Ptr<UniformRandomVariable> u = CreateObject<UniformRandomVariable> (); |
118 double result = ChiSquaredTest (u); | 126 double result = ChiSquaredTest (u); |
119 sum += result; | 127 sum += result; |
120 } | 128 } |
121 | 129 |
122 sum /= (double)N_RUNS; | 130 sum /= (double)N_RUNS; |
123 | 131 |
124 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); | 132 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); |
125 } | 133 } |
126 | 134 |
127 // =========================================================================== | 135 /** |
128 // Test case for normal distribution random number generator | 136 * \ingroup core-test |
129 // =========================================================================== | 137 * \ingroup tests |
| 138 * |
| 139 * \brief Test case for normal distribution random number generator |
| 140 */ |
130 class RngNormalTestCase : public TestCase | 141 class RngNormalTestCase : public TestCase |
131 { | 142 { |
132 public: | 143 public: |
133 static const uint32_t N_RUNS = 5; | 144 static const uint32_t N_RUNS = 5; ///< number of runs |
134 static const uint32_t N_BINS = 50; | 145 static const uint32_t N_BINS = 50; ///< number of bins |
135 static const uint32_t N_MEASUREMENTS = 1000000; | 146 static const uint32_t N_MEASUREMENTS = 1000000; ///< number of measurements |
136 | 147 |
137 RngNormalTestCase (); | 148 RngNormalTestCase (); |
138 virtual ~RngNormalTestCase (); | 149 virtual ~RngNormalTestCase (); |
139 | 150 |
| 151 /** |
| 152 * Chi squared test function |
| 153 * \param n The normal random value |
| 154 * \returns the chi squared value |
| 155 */ |
140 double ChiSquaredTest (Ptr<NormalRandomVariable> n); | 156 double ChiSquaredTest (Ptr<NormalRandomVariable> n); |
141 | 157 |
142 private: | 158 private: |
143 virtual void DoRun (void); | 159 virtual void DoRun (void); |
144 }; | 160 }; |
145 | 161 |
146 RngNormalTestCase::RngNormalTestCase () | 162 RngNormalTestCase::RngNormalTestCase () |
147 : TestCase ("Normal Random Number Generator") | 163 : TestCase ("Normal Random Number Generator") |
148 { | 164 { |
149 } | 165 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Ptr<NormalRandomVariable> n = CreateObject<NormalRandomVariable> (); | 230 Ptr<NormalRandomVariable> n = CreateObject<NormalRandomVariable> (); |
215 double result = ChiSquaredTest (n); | 231 double result = ChiSquaredTest (n); |
216 sum += result; | 232 sum += result; |
217 } | 233 } |
218 | 234 |
219 sum /= (double)N_RUNS; | 235 sum /= (double)N_RUNS; |
220 | 236 |
221 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); | 237 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); |
222 } | 238 } |
223 | 239 |
224 // =========================================================================== | 240 /** |
225 // Test case for exponential distribution random number generator | 241 * \ingroup core-test |
226 // =========================================================================== | 242 * \ingroup tests |
| 243 * |
| 244 * \brief Test case for exponential distribution random number generator |
| 245 */ |
227 class RngExponentialTestCase : public TestCase | 246 class RngExponentialTestCase : public TestCase |
228 { | 247 { |
229 public: | 248 public: |
230 static const uint32_t N_RUNS = 5; | 249 static const uint32_t N_RUNS = 5; ///< number of runs |
231 static const uint32_t N_BINS = 50; | 250 static const uint32_t N_BINS = 50; ///< number of bins |
232 static const uint32_t N_MEASUREMENTS = 1000000; | 251 static const uint32_t N_MEASUREMENTS = 1000000; ///< number of measurements |
233 | 252 |
234 RngExponentialTestCase (); | 253 RngExponentialTestCase (); |
235 virtual ~RngExponentialTestCase (); | 254 virtual ~RngExponentialTestCase (); |
236 | 255 |
| 256 /** |
| 257 * Chi squared test function |
| 258 * \param n The exponential random value |
| 259 * \returns the chi squared value |
| 260 */ |
237 double ChiSquaredTest (Ptr<ExponentialRandomVariable> n); | 261 double ChiSquaredTest (Ptr<ExponentialRandomVariable> n); |
238 | 262 |
239 private: | 263 private: |
240 virtual void DoRun (void); | 264 virtual void DoRun (void); |
241 }; | 265 }; |
242 | 266 |
243 RngExponentialTestCase::RngExponentialTestCase () | 267 RngExponentialTestCase::RngExponentialTestCase () |
244 : TestCase ("Exponential Random Number Generator") | 268 : TestCase ("Exponential Random Number Generator") |
245 { | 269 { |
246 } | 270 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 Ptr<ExponentialRandomVariable> e = CreateObject<ExponentialRandomVariable>
(); | 334 Ptr<ExponentialRandomVariable> e = CreateObject<ExponentialRandomVariable>
(); |
311 double result = ChiSquaredTest (e); | 335 double result = ChiSquaredTest (e); |
312 sum += result; | 336 sum += result; |
313 } | 337 } |
314 | 338 |
315 sum /= (double)N_RUNS; | 339 sum /= (double)N_RUNS; |
316 | 340 |
317 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); | 341 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); |
318 } | 342 } |
319 | 343 |
320 // =========================================================================== | 344 /** |
321 // Test case for pareto distribution random number generator | 345 * \ingroup core-test |
322 // =========================================================================== | 346 * \ingroup tests |
| 347 * |
| 348 * \brief Test case for pareto distribution random number generator |
| 349 */ |
323 class RngParetoTestCase : public TestCase | 350 class RngParetoTestCase : public TestCase |
324 { | 351 { |
325 public: | 352 public: |
326 static const uint32_t N_RUNS = 5; | 353 static const uint32_t N_RUNS = 5; ///< number of runs |
327 static const uint32_t N_BINS = 50; | 354 static const uint32_t N_BINS = 50; ///< number of bins |
328 static const uint32_t N_MEASUREMENTS = 1000000; | 355 static const uint32_t N_MEASUREMENTS = 1000000; ///< number of measurements |
329 | 356 |
330 RngParetoTestCase (); | 357 RngParetoTestCase (); |
331 virtual ~RngParetoTestCase (); | 358 virtual ~RngParetoTestCase (); |
332 | 359 |
| 360 /** |
| 361 * Chi squared test function |
| 362 * \param p The pareto random value |
| 363 * \returns the chi squared value |
| 364 */ |
333 double ChiSquaredTest (Ptr<ParetoRandomVariable> p); | 365 double ChiSquaredTest (Ptr<ParetoRandomVariable> p); |
334 | 366 |
335 private: | 367 private: |
336 virtual void DoRun (void); | 368 virtual void DoRun (void); |
337 }; | 369 }; |
338 | 370 |
339 RngParetoTestCase::RngParetoTestCase () | 371 RngParetoTestCase::RngParetoTestCase () |
340 : TestCase ("Pareto Random Number Generator") | 372 : TestCase ("Pareto Random Number Generator") |
341 { | 373 { |
342 } | 374 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 e->SetAttribute ("Scale", DoubleValue (0.33333333)); | 443 e->SetAttribute ("Scale", DoubleValue (0.33333333)); |
412 double result = ChiSquaredTest (e); | 444 double result = ChiSquaredTest (e); |
413 sum += result; | 445 sum += result; |
414 } | 446 } |
415 | 447 |
416 sum /= (double)N_RUNS; | 448 sum /= (double)N_RUNS; |
417 | 449 |
418 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); | 450 NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range"
); |
419 } | 451 } |
420 | 452 |
| 453 /** |
| 454 * \ingroup core-test |
| 455 * \ingroup tests |
| 456 * |
| 457 * \brief Range test suite |
| 458 */ |
421 class RngTestSuite : public TestSuite | 459 class RngTestSuite : public TestSuite |
422 { | 460 { |
423 public: | 461 public: |
424 RngTestSuite (); | 462 RngTestSuite (); |
425 }; | 463 }; |
426 | 464 |
427 RngTestSuite::RngTestSuite () | 465 RngTestSuite::RngTestSuite () |
428 : TestSuite ("random-number-generators", UNIT) | 466 : TestSuite ("random-number-generators", UNIT) |
429 { | 467 { |
430 AddTestCase (new RngUniformTestCase, TestCase::QUICK); | 468 AddTestCase (new RngUniformTestCase, TestCase::QUICK); |
431 AddTestCase (new RngNormalTestCase, TestCase::QUICK); | 469 AddTestCase (new RngNormalTestCase, TestCase::QUICK); |
432 AddTestCase (new RngExponentialTestCase, TestCase::QUICK); | 470 AddTestCase (new RngExponentialTestCase, TestCase::QUICK); |
433 AddTestCase (new RngParetoTestCase, TestCase::QUICK); | 471 AddTestCase (new RngParetoTestCase, TestCase::QUICK); |
434 } | 472 } |
435 | 473 |
436 static RngTestSuite rngTestSuite; | 474 static RngTestSuite rngTestSuite; |
LEFT | RIGHT |