MediaWiki
REL1_22
|
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 # Revision 33 new operand examples 00083 # expected, rule, number, comment 00084 array( 0, 'i is 1', '1.00', 'new operand i' ), 00085 array( 0, 'v is 2', '1.00', 'new operand v' ), 00086 array( 0, 'w is 0', '1.00', 'new operand w' ), 00087 array( 0, 'f is 0', '1.00', 'new operand f' ), 00088 array( 0, 't is 0', '1.00', 'new operand t' ), 00089 00090 array( 0, 'i is 1', '1.30', 'new operand i' ), 00091 array( 0, 'v is 2', '1.30', 'new operand v' ), 00092 array( 0, 'w is 1', '1.30', 'new operand w' ), 00093 array( 0, 'f is 30', '1.30', 'new operand f' ), 00094 array( 0, 't is 3', '1.30', 'new operand t' ), 00095 00096 array( 0, 'i is 1', '1.03', 'new operand i' ), 00097 array( 0, 'v is 2', '1.03', 'new operand v' ), 00098 array( 0, 'w is 2', '1.03', 'new operand w' ), 00099 array( 0, 'f is 3', '1.03', 'new operand f' ), 00100 array( 0, 't is 3', '1.03', 'new operand t' ), 00101 00102 # Revision 33 new operator aliases 00103 # expected, rule, number, comment 00104 array( 0, 'n % 3 is 1', 7, 'new % operator' ), 00105 array( 0, 'n = 1,3,5', 3, 'new = operator' ), 00106 array( 1, 'n != 1,3,5', 5, 'new != operator' ), 00107 00108 # Revision 33 samples 00109 # expected, rule, number, comment 00110 array( 0, 'n in 1,3,5@integer 3~10, 103~110, 1003, … @decimal 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, …', 3, 'samples' ), 00111 00112 # Revision 33 some test cases from CLDR 00113 array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ), 00114 array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ), 00115 array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ), 00116 array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ), 00117 array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ), 00118 array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ), 00119 array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ), 00120 array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ), 00121 array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ), 00122 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '2', 'bs few' ), 00123 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '4', 'bs few' ), 00124 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '22', 'bs few' ), 00125 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '102', 'bs few' ), 00126 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.2', 'bs few' ), 00127 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '0.4', 'bs few' ), 00128 array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.2', 'bs few' ), 00129 array( 1, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.0', 'bs other' ), 00130 00131 ); 00132 00133 return $tests; 00134 } 00135 00136 function invalidTestCases() { 00137 $tests = array( 00138 array( 'n mod mod 5 is 1', 'mod mod' ), 00139 array( 'n', 'just n' ), 00140 array( 'n is in 5', 'is in' ), 00141 ); 00142 00143 return $tests; 00144 } 00145 }