MediaWiki  REL1_20
CLDRPluralRuleEvaluatorTest.php
Go to the documentation of this file.
00001 <?php
00007 class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase {
00011         function testValidRules( $expected, $rules, $number, $comment ) {
00012                 $result = CLDRPluralRuleEvaluator::evaluate( $number, (array) $rules );
00013                 $this->assertEquals( $expected, $result, $comment );
00014         }
00015 
00020         function testInvalidRules( $rules, $comment ) {
00021                 CLDRPluralRuleEvaluator::evaluate( 1, (array) $rules );
00022         }
00023 
00024         function validTestCases() {
00025                 $tests = array(
00026                         # expected, number, rule, comment
00027                         array( 0, 'n is 1', 1, 'integer number and is' ),
00028                         array( 0, 'n is 1', "1", 'string integer number and is' ),
00029                         array( 0, 'n is 1', 1.0, 'float number and is' ),
00030                         array( 0, 'n is 1', "1.0", 'string float number and is' ),
00031                         array( 1, 'n is 1', 1.1, 'float number and is' ),
00032                         array( 1, 'n is 1', 2, 'float number and is' ),
00033 
00034                         array( 0, 'n in 1,3,5',     3, '' ),
00035                         array( 1, 'n not in 1,3,5', 5, '' ),
00036 
00037                         array( 1, 'n in 1,3,5',     2, '' ),
00038                         array( 0, 'n not in 1,3,5', 4, '' ),
00039 
00040                         array( 0, 'n in 1..3',      2, '' ),
00041                         array( 0, 'n in 1..3',      3, 'in is inclusive' ),
00042                         array( 1, 'n in 1..3',      0, '' ),
00043 
00044                         array( 1, 'n not in 1..3',      2, '' ),
00045                         array( 1, 'n not in 1..3',      3, 'in is inclusive' ),
00046                         array( 0, 'n not in 1..3',      0, '' ),
00047 
00048                         array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ),
00049                         array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ),
00050 
00051                         array( 0, 'n is not 1 or n is 1', 1, 'or relation' ),
00052                         array( 1, 'n is 1 or n is 2', 3, 'or relation' ),
00053 
00054                         array( 0, 'n              is      1', 1, 'extra whitespace' ),
00055 
00056                         array( 0, 'n mod 3 is 1', 7, 'mod' ),
00057                         array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ),
00058 
00059                         array( 0, 'n within 1..3', 2, 'within with integer' ),
00060                         array( 0, 'n within 1..3', 2.5, 'within with float' ),
00061                         array( 0, 'n in 1..3', 2, 'in with integer' ),
00062                         array( 1, 'n in 1..3', 2.5, 'in with float' ),
00063 
00064                         array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ),
00065                         array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ),
00066 
00067                         array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ),
00068                         array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ),
00069 
00070                         array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ),
00071                         array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ),
00072                         array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ),
00073                         array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ),
00074 
00075                         array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ),
00076                         array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ),
00077                         array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ),
00078                         array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ),
00079 
00080                         array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ),
00081                 );
00082 
00083                 return $tests;
00084         }
00085 
00086         function invalidTestCases() {
00087                 $tests = array(
00088                         array( 'n mod mod 5 is 1', 'mod mod' ),
00089                         array( 'n', 'just n' ),
00090                         array( 'n is in 5', 'is in' ),
00091                 );
00092                 return $tests;
00093         }
00094 
00095 }