示例#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
文件: RoundTest.php 项目: krixon/math
 /**
  * @dataProvider roundProvider
  * @covers       ::round
  *
  * @param mixed  $decimal
  * @param int    $decimalPlaces
  * @param string $expected
  */
 public function testCanRound($decimal, int $decimalPlaces, string $expected)
 {
     $decimal = Decimal::create($decimal);
     $rounded = $decimal->round($decimalPlaces);
     self::assertSame($expected, $rounded->toString());
 }
示例#5
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()));
 }
示例#6
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());
 }
示例#7
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());
 }
示例#8
0
文件: AbsTest.php 项目: krixon/math
 /**
  * @dataProvider absProvider
  * @covers       ::abs
  *
  * @param mixed  $decimal
  * @param string $expected
  */
 public function testCanGetAbsoluteValue($decimal, string $expected)
 {
     $decimal = Decimal::create($decimal);
     $absolute = $decimal->abs();
     self::assertSame($expected, $absolute->toString());
 }
示例#9
0
 /**
  * @covers ::one
  */
 public function testCanCreateOne()
 {
     $one = Decimal::one();
     self::assertSame('1', $one->toString());
     self::assertSame($one, Decimal::one());
 }