/** * Test Failure Counting. * * @covers \DrupalReleaseDate\EstimateDistribution::__construct * @covers \DrupalReleaseDate\EstimateDistribution::failure * @covers \DrupalReleaseDate\EstimateDistribution::getFailureCount */ public function testFailureCount() { $estimates = new EstimateDistribution(); $this->assertEquals(0, $estimates->getFailureCount()); $estimates->failure(); $this->assertEquals(1, $estimates->getFailureCount()); $estimates->failure(); $estimates->failure(); $this->assertEquals(3, $estimates->getFailureCount()); }
/** * 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; }