Skip to content

Commit

Permalink
Add RationalMoney::simplified() method
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Oct 9, 2018
1 parent 2b87687 commit 969b8c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/RationalMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public function dividedBy($that) : RationalMoney
return new self($amount, $this->currency);
}

/**
* Returns a copy of this BigRational, with the amount simplified.
*
* @return RationalMoney
*/
public function simplified() : RationalMoney
{
return new self($this->amount->simplified(), $this->currency);
}

/**
* @return string
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/RationalMoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,33 @@ public function providerDividedBy()
];
}

/**
* @dataProvider providerSimplified
*
* @param array $rationalMoney
* @param string $expected
*/
public function testSimplified(array $rationalMoney, $expected)
{
$rationalMoney = RationalMoney::of(...$rationalMoney);

$actual = $rationalMoney->simplified();
$this->assertRationalMoneyEquals($expected, $actual);
}

/**
* @return array
*/
public function providerSimplified() : array
{
return [
[['123456/10000', 'USD'], 'USD 7716/625'],
[['695844/45600', 'CAD'], 'CAD 57987/3800'],
[['368022/405840', 'EUR'], 'EUR 61337/67640'],
[['-671244/45600', 'GBP'], 'GBP -55937/3800'],
];
}

/**
* @dataProvider providerTo
*
Expand Down

0 comments on commit 969b8c3

Please sign in to comment.