Ejemplo n.º 1
0
 /**
  * @dataProvider decimalToExpectedRatioProvider
  * @covers ::toRatio
  *
  * @param string $decimal
  * @param string $expected
  */
 public function testCanConvertToRatio(string $decimal, string $expected)
 {
     $decimal = Decimal::fromString($decimal);
     $ratio = $decimal->toRatio();
     self::assertInstanceOf(Ratio::class, $ratio);
     self::assertSame($expected, $ratio->toString());
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider divideByProvider
  * @covers       ::divideBy
  *
  * @param string $a
  * @param string $b
  * @param string $expected
  * @param int    $scale
  */
 public function testDivideBy(string $a, string $b, string $expected, $scale = null)
 {
     $a = Decimal::fromString($a);
     $b = Decimal::fromString($b);
     $expected = Decimal::fromString($expected);
     $result = $a->divideBy($b, $scale);
     self::assertTrue($result->equals($expected), "{$a} ÷ {$b} != {$expected} (actual: {$result})");
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider plusProvider
  * @covers       ::plus
  *
  * @param string $a
  * @param string $b
  * @param string $expected
  * @param int    $scale
  */
 public function testPlus(string $a, string $b, string $expected, $scale = Decimal::SCALE)
 {
     $a = Decimal::fromString($a);
     $b = Decimal::fromString($b);
     $expected = Decimal::fromString($expected);
     $result = $a->plus($b, $scale);
     self::assertTrue($result->equals($expected), "{$a} + {$b} != {$expected} (actual: {$result})");
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider greatestCommonDivisorProvider
  * @covers ::greatestCommonDivisor
  *
  * @param string $ratio
  * @param int    $expected
  */
 public function testCanCalculateGreatestCommonDivisor($ratio, $expected)
 {
     $ratio = Ratio::fromString($ratio);
     $expected = Decimal::fromString($expected);
     $result = $ratio->greatestCommonDivisor();
     self::assertInstanceOf(Decimal::class, $result);
     self::assertTrue($expected->equals($result), sprintf('Decimal with value %s is not equal to expected Decimal with value %s', $result->toString(), $expected->toString()));
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider significantDigitsProvider
  * @covers ::numberOfSignificantDigits
  *
  * @param string $input
  * @param int    $expected
  */
 public function testCanGetNumberOfSignificantDigits(string $input, int $expected)
 {
     self::assertSame($expected, Decimal::fromString($input)->numberOfSignificantDigits());
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider determineIfOneProvider
  * @covers       ::isOne
  *
  * @param string $decimal
  * @param bool   $expected
  */
 public function testCanDetermineIfOne(string $decimal, bool $expected)
 {
     $decimal = Decimal::fromString($decimal);
     self::assertSame($expected, $decimal->isOne());
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider stringProvider
  * @covers ::create
  *
  * @param string $decimal
  */
 public function testCreateDelegatesToStaticStringFactory(string $decimal)
 {
     self::assertTrue(Decimal::create($decimal)->equals(Decimal::fromString($decimal)));
 }