/** * @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 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 stringProvider * @covers ::create * * @param string $decimal */ public function testCreateDelegatesToStaticStringFactory(string $decimal) { self::assertTrue(Decimal::create($decimal)->equals(Decimal::fromString($decimal))); }