View | Details | Raw Unified | Return to bug 1927
Collapse All | Expand All

(-)a/src/core/test/random-variable-stream-test-suite.cc (-10 / +19 lines)
 Lines 112-121    Link Here 
112
class RandomVariableStreamUniformTestCase : public TestCase
112
class RandomVariableStreamUniformTestCase : public TestCase
113
{
113
{
114
public:
114
public:
115
  static const uint32_t N_RUNS = 5;
115
  // We want the number of observations in each bin to be > 5
116
  static const uint32_t N_BINS = 50;
116
  // The following values should yield many more than 5 per bin
117
  static const uint32_t N_BINS = 100;
117
  static const uint32_t N_MEASUREMENTS = 1000000;
118
  static const uint32_t N_MEASUREMENTS = 1000000;
118
119
120
  // Number of times to wrap the Chi-Squared test and retry
121
  static const uint32_t N_RUNS = 2;
122
119
  RandomVariableStreamUniformTestCase ();
123
  RandomVariableStreamUniformTestCase ();
120
  virtual ~RandomVariableStreamUniformTestCase ();
124
  virtual ~RandomVariableStreamUniformTestCase ();
121
125
 Lines 177-195    Link Here 
177
{
181
{
178
  SetTestSuiteSeed ();
182
  SetTestSuiteSeed ();
179
183
180
  double sum = 0.;
184
  double confidence = 0.99;
181
  double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
185
  double maxStatistic = gsl_cdf_chisq_Pinv (confidence, (N_BINS-1));
182
186
  NS_LOG_DEBUG ("Chi square required at " << confidence << " confidence for " << N_BINS << " bins is " << maxStatistic);
187
188
  double result = maxStatistic;
189
  // If chi-squared test fails, re-try it up to N_RUNS times
183
  for (uint32_t i = 0; i < N_RUNS; ++i)
190
  for (uint32_t i = 0; i < N_RUNS; ++i)
184
    {
191
    {
185
      Ptr<UniformRandomVariable> u = CreateObject<UniformRandomVariable> ();
192
      Ptr<UniformRandomVariable> u = CreateObject<UniformRandomVariable> ();
186
      double result = ChiSquaredTest (u);
193
      result = ChiSquaredTest (u);
187
      sum += result;
194
      NS_LOG_DEBUG ("Chi square result is " << result);
195
      if (result < maxStatistic)
196
        {
197
          break;
198
        }
188
    }
199
    }
189
200
190
  sum /= (double)N_RUNS;
201
  NS_TEST_ASSERT_MSG_LT (result, maxStatistic, "Chi-squared statistic out of range");
191
192
  NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
193
202
194
  double min = 0.0;
203
  double min = 0.0;
195
  double max = 10.0;
204
  double max = 10.0;

Return to bug 1927