コード例 #1
0
ファイル: BigDecimalTest.php プロジェクト: nicholas-eden/math
 /**
  * @param int         $roundingMode The rounding mode.
  * @param BigDecimal  $number       The number to round.
  * @param string      $divisor      The divisor.
  * @param string|null $two          The expected rounding to a scale of two, or null if an exception is expected.
  * @param string|null $one          The expected rounding to a scale of one, or null if an exception is expected.
  * @param string|null $zero         The expected rounding to a scale of zero, or null if an exception is expected.
  */
 private function doTestRoundingMode($roundingMode, BigDecimal $number, $divisor, $two, $one, $zero)
 {
     foreach ([$zero, $one, $two] as $scale => $expected) {
         if ($expected === null) {
             $this->setExpectedException(RoundingNecessaryException::getNamespace());
         }
         $actual = $number->dividedBy($divisor, $scale, $roundingMode);
         if ($expected !== null) {
             $this->assertBigDecimalInternalValues($expected, $scale, $actual);
         }
     }
 }
コード例 #2
0
ファイル: BigIntegerTest.php プロジェクト: nicholas-eden/math
 /**
  * @param integer     $roundingMode The rounding mode.
  * @param BigInteger  $number       The number to round.
  * @param string      $divisor      The divisor.
  * @param string|null $ten          The expected rounding to a scale of two, or null if an exception is expected.
  * @param string|null $hundred          The expected rounding to a scale of one, or null if an exception is expected.
  * @param string|null $thousand         The expected rounding to a scale of zero, or null if an exception is expected.
  */
 private function doTestDividedByWithRoundingMode($roundingMode, BigInteger $number, $divisor, $ten, $hundred, $thousand)
 {
     foreach ([$ten, $hundred, $thousand] as $expected) {
         $divisor .= '0';
         if ($expected === null) {
             $this->setExpectedException(RoundingNecessaryException::getNamespace());
         }
         $actual = $number->dividedBy($divisor, $roundingMode);
         if ($expected !== null) {
             $this->assertBigIntegerEquals($expected, $actual);
         }
     }
 }
コード例 #3
0
 /**
  * @return array
  */
 public function providerToScale()
 {
     return [['1/8', 3, RoundingMode::UNNECESSARY, '0.125'], ['1/16', 3, RoundingMode::UNNECESSARY, RoundingNecessaryException::getNamespace()], ['1/16', 3, RoundingMode::HALF_DOWN, '0.062'], ['1/16', 3, RoundingMode::HALF_UP, '0.063'], ['1/9', 30, RoundingMode::DOWN, '0.111111111111111111111111111111'], ['1/9', 30, RoundingMode::UP, '0.111111111111111111111111111112'], ['1/9', 100, RoundingMode::UNNECESSARY, RoundingNecessaryException::getNamespace()]];
 }