Skip to content

Commit

Permalink
Merge pull request #5 from alexlcdee/fix-hundreds
Browse files Browse the repository at this point in the history
Fix plurality for numbers more than 100.
  • Loading branch information
wapmorgan authored Jun 13, 2017
2 parents 6d76efe + b869d07 commit 713da11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Russian/Plurality.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ static public function pluralize($word, $count = 2, $animateness = false) {
}

static public function getNumeralForm($count) {
if($count > 100) {
$count %= 100;
}
$ending = $count % 10;
if (($count > 20 && $ending == 1) || $count == 1)
return self::ONE;
Expand Down
15 changes: 15 additions & 0 deletions tests/Russian/PluralityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@ class PluralityTest extends \PHPUnit_Framework_TestCase {
* @dataProvider pluralizationWordsProvider
*/
public function testPluralization($word, $pluralized2, $pluralized5) {
// One
$this->assertEquals($word, Plurality::pluralize($word, 1));
$this->assertEquals($word, Plurality::pluralize($word, 101));
$this->assertEquals($word, Plurality::pluralize($word, 201));
$this->assertEquals($word, Plurality::pluralize($word, 1501));

// Two-Four
$this->assertEquals($pluralized2, Plurality::pluralize($word, 2));
$this->assertEquals($pluralized2, Plurality::pluralize($word, 23));
$this->assertEquals($pluralized2, Plurality::pluralize($word, 104));
$this->assertEquals($pluralized2, Plurality::pluralize($word, 1503));

// Five
$this->assertEquals($pluralized5, Plurality::pluralize($word, 5));
$this->assertEquals($pluralized5, Plurality::pluralize($word, 211));
$this->assertEquals($pluralized5, Plurality::pluralize($word, 520));
$this->assertEquals($pluralized5, Plurality::pluralize($word, 1513));
}

public function pluralizationWordsProvider() {
Expand Down

0 comments on commit 713da11

Please sign in to comment.