示例#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());
 }
示例#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})");
 }
示例#3
0
文件: PlusTest.php 项目: krixon/math
 /**
  * @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})");
 }
示例#4
0
文件: RatioTest.php 项目: krixon/math
 /**
  * @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()));
 }
示例#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());
 }
示例#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());
 }
示例#7
0
 /**
  * @dataProvider stringProvider
  * @covers ::create
  *
  * @param string $decimal
  */
 public function testCreateDelegatesToStaticStringFactory(string $decimal)
 {
     self::assertTrue(Decimal::create($decimal)->equals(Decimal::fromString($decimal)));
 }