Ejemplo n.º 1
0
 /**
  * @test
  */
 public function I_can_round_a_number()
 {
     $shouldBeHigher = 4.5;
     $this->assertSame(5, SumAndRound::round($shouldBeHigher));
     $shouldBeLower = 4.4;
     $this->assertSame(4, SumAndRound::round($shouldBeLower));
 }
 /**
  * @param RidingAnimalCode $ridingAnimalCode
  * @param DefianceOfWildPercents $defianceOfWildPercents
  * @param bool $jumpingAndDangerousMoves
  * @return int
  */
 public function getDefianceOfWild(RidingAnimalCode $ridingAnimalCode, DefianceOfWildPercents $defianceOfWildPercents, $jumpingAndDangerousMoves)
 {
     $defianceOfDomesticated = $this->getDefianceOfDomesticated($ridingAnimalCode, $jumpingAndDangerousMoves);
     $additionForWild = SumAndRound::round(10 + 2 * $defianceOfWildPercents->getRate());
     // 10..12
     return $defianceOfDomesticated + $additionForWild;
 }
 /**
  * @param $terrainCode
  * @param TerrainDifficultyPercents $difficultyPercents
  * @return int
  * @throws \DrdPlus\Tables\Environments\Exceptions\UnknownTerrainCode
  * @throws \DrdPlus\Tables\Environments\Exceptions\InvalidTerrainCodeFormat
  */
 private function getSpeedMalusValueForTerrain($terrainCode, TerrainDifficultyPercents $difficultyPercents)
 {
     // value is zero or negative, so bonus is de facto malus
     $range = $this->getSpeedMalusValuesRangeForTerrain($terrainCode);
     $difference = $range[self::IMPASSIBILITY_OF_TERRAIN_TO] - $range[self::IMPASSIBILITY_OF_TERRAIN_FROM];
     $addition = $difference * $difficultyPercents->getRate();
     return SumAndRound::round($range[self::IMPASSIBILITY_OF_TERRAIN_FROM] + $addition);
 }
 /**
  * @param string $code
  * @param Percents $percents
  * @return int
  * @throws \DrdPlus\Tables\Partials\Exceptions\UnexpectedPercents
  * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType
  * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredRowNotFound
  */
 protected function getBonusBy($code, Percents $percents)
 {
     if ($percents->getValue() > 100 && !$this->canBeMore($code)) {
         throw new Exceptions\UnexpectedPercents('For ' . ValueDescriber::describe($code) . " can be percents of addition only between zero and one hundred, got {$percents}");
     }
     $bonusFrom = $this->getBonusBorder($code, self::BONUS_FROM);
     $bonusTo = $this->getBonusBorder($code, self::BONUS_TO);
     if ($bonusFrom < $bonusTo) {
         // has to swap start and end
         list($bonusFrom, $bonusTo) = [$bonusTo, $bonusFrom];
     }
     $difference = $bonusTo - $bonusFrom;
     $addition = $difference * $percents->getRate();
     $totalBonus = $bonusFrom + $addition;
     return SumAndRound::round($totalBonus);
 }