/** * @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()); }
/** * @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})"); }
/** * @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})"); }
/** * @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()); }
/** * @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())); }
/** * @dataProvider significantDigitsProvider * @covers ::numberOfSignificantDigits * * @param string $input * @param int $expected */ public function testCanGetNumberOfSignificantDigits(string $input, int $expected) { self::assertSame($expected, Decimal::fromString($input)->numberOfSignificantDigits()); }
/** * @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()); }
/** * @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()); }
/** * @covers ::one */ public function testCanCreateOne() { $one = Decimal::one(); self::assertSame('1', $one->toString()); self::assertSame($one, Decimal::one()); }