From 266c6e85152469f73c97ccaac43bb80db4711f90 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Mon, 9 Jan 2012 12:46:53 +0000 Subject: [PATCH] Cleanup the convertPLural method for Lithuanian(lt) Add phpunit test cases. --- languages/classes/LanguageLt.php | 8 ++--- tests/phpunit/languages/LanguageLtTest.php | 36 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/phpunit/languages/LanguageLtTest.php diff --git a/languages/classes/LanguageLt.php b/languages/classes/LanguageLt.php index 09cacae02b..9b4634266e 100644 --- a/languages/classes/LanguageLt.php +++ b/languages/classes/LanguageLt.php @@ -12,6 +12,7 @@ class LanguageLt extends Language { */ /** + * Lithuanian plural forms as per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#lt * @param $count int * @param $forms array * @@ -19,13 +20,10 @@ class LanguageLt extends Language { */ function convertPlural( $count, $forms ) { if ( !count( $forms ) ) { return ''; } - - // if no number with word, then use $form[0] for singular and $form[1] for plural or zero - if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1]; - $forms = $this->preConvertPlural( $forms, 3 ); - + // Form[0] if n mod 10 is 1 and n mod 100 not in 11..19; if ( $count % 10 == 1 && $count % 100 != 11 ) return $forms[0]; + // Forms[1] if n mod 10 in 2..9 and n mod 100 not in 11..19; if ( $count % 10 >= 2 && ( $count % 100 < 10 || $count % 100 >= 20 ) ) return $forms[1]; return $forms[2]; } diff --git a/tests/phpunit/languages/LanguageLtTest.php b/tests/phpunit/languages/LanguageLtTest.php new file mode 100644 index 0000000000..38ea933a05 --- /dev/null +++ b/tests/phpunit/languages/LanguageLtTest.php @@ -0,0 +1,36 @@ +lang = Language::factory( 'Lt' ); + } + function tearDown() { + unset( $this->lang ); + } + + function testPlural() { + $forms = array( 'one', 'few', 'other' ); + $this->assertEquals( 'other', $this->lang->convertPlural( 0, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 1, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 2, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 9, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 10, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 11, $forms ) ); + $this->assertEquals( 'other', $this->lang->convertPlural( 20, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 21, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 32, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 41, $forms ) ); + $this->assertEquals( 'one', $this->lang->convertPlural( 40001, $forms ) ); + $forms = array( 'one', 'few' ); + $this->assertEquals( 'one', $this->lang->convertPlural( 1, $forms ) ); + $this->assertEquals( 'few', $this->lang->convertPlural( 15, $forms ) ); + } +} -- 2.20.1