コード例 #1
0
 /**
  * Get the distribution of estimates from the specified number of
  * iterations, grouped into buckets of the specified size.
  *
  * @param int $iterations
  * @param int $bucketSize
  *   The period in seconds to group estimates by.
  * @param int $timeLimit
  *   The number of seconds to allow the estimation to run for.
  * @return EstimateDistribution
  */
 public function runDistribution($iterations = self::DEFAULT_ITERATIONS, $bucketSize = self::DEFAULT_BUCKET_SIZE, $timeLimit = self::DEFAULT_TIME_LIMIT)
 {
     $estimates = new EstimateDistribution();
     $abortTime = time() + $timeLimit;
     for ($run = 1; $run <= $iterations; $run++) {
         try {
             $estimate = $this->iteration($abortTime);
             $bucket = $estimate - $estimate % $bucketSize;
             $estimates->success($bucket);
         } catch (IncreasingException $e) {
             $estimates->failure();
             if ($run > $iterations * $this->increasingFailureThresholdRatio && $estimates->getFailureCount() / $run > $this->increasingFailureRatio) {
                 $runException = new IncreasingException('Run aborted after iteration ' . $run, 0, $e);
                 $runException->setDistribution($estimates);
                 throw $runException;
             }
         } catch (TimeoutException $e) {
             $estimates->failure();
             $runException = new TimeoutException('Run aborted during iteration ' . $run, 0, $e);
             $runException->setDistribution($estimates);
             throw $runException;
         }
     }
     return $estimates;
 }
コード例 #2
0
 /**
  * Test a median when failures are included in the calculation
  *
  * @expectedException \RuntimeException
  *
  * @covers \DrupalReleaseDate\EstimateDistribution::getMedian
  * @uses \DrupalReleaseDate\EstimateDistribution::__construct
  * @uses \DrupalReleaseDate\EstimateDistribution::success
  */
 public function testMedianWithTooManyFailures()
 {
     $estimates = new EstimateDistribution();
     $estimates->success(1);
     $estimates->success(2);
     $estimates->success(3);
     $estimates->failure();
     $estimates->failure();
     $estimates->failure();
     $estimates->failure();
     $estimates->getMedian(true);
 }