Cleanup the convertPLural method for Lithuanian(lt)
authorSanthosh Thottingal <santhosh@users.mediawiki.org>
Mon, 9 Jan 2012 12:46:53 +0000 (12:46 +0000)
committerSanthosh Thottingal <santhosh@users.mediawiki.org>
Mon, 9 Jan 2012 12:46:53 +0000 (12:46 +0000)
Add phpunit test cases.

languages/classes/LanguageLt.php
tests/phpunit/languages/LanguageLtTest.php [new file with mode: 0644]

index 09cacae..9b46342 100644 (file)
@@ -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 (file)
index 0000000..38ea933
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2012, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageLt.php */
+class LanguageLtTest extends MediaWikiTestCase {
+       private $lang;
+
+       function setUp() {
+               $this->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 ) );
+       }
+}