Merge "Declare visibility on class props of MediaTransformOutput and MediaTransformError"
[mediawiki.git] / tests / phpunit / languages / utils / CLDRPluralRuleEvaluatorTest.php
blob6abd09f2846f27aea9d83a1b18e609381e7af45a
1 <?php
2 /**
3 * @author Niklas Laxström
4 * @file
5 */
7 /**
8 * @covers CLDRPluralRuleEvaluator
9 */
10 class CLDRPluralRuleEvaluatorTest extends MediaWikiTestCase {
11 /**
12 * @dataProvider validTestCases
14 function testValidRules( $expected, $rules, $number, $comment ) {
15 $result = CLDRPluralRuleEvaluator::evaluate( $number, (array)$rules );
16 $this->assertEquals( $expected, $result, $comment );
19 /**
20 * @dataProvider invalidTestCases
21 * @expectedException CLDRPluralRuleError
23 function testInvalidRules( $rules, $comment ) {
24 CLDRPluralRuleEvaluator::evaluate( 1, (array)$rules );
27 function validTestCases() {
28 $tests = array(
29 # expected, rule, number, comment
30 array( 0, 'n is 1', 1, 'integer number and is' ),
31 array( 0, 'n is 1', "1", 'string integer number and is' ),
32 array( 0, 'n is 1', 1.0, 'float number and is' ),
33 array( 0, 'n is 1', "1.0", 'string float number and is' ),
34 array( 1, 'n is 1', 1.1, 'float number and is' ),
35 array( 1, 'n is 1', 2, 'float number and is' ),
37 array( 0, 'n in 1,3,5', 3, '' ),
38 array( 1, 'n not in 1,3,5', 5, '' ),
40 array( 1, 'n in 1,3,5', 2, '' ),
41 array( 0, 'n not in 1,3,5', 4, '' ),
43 array( 0, 'n in 1..3', 2, '' ),
44 array( 0, 'n in 1..3', 3, 'in is inclusive' ),
45 array( 1, 'n in 1..3', 0, '' ),
47 array( 1, 'n not in 1..3', 2, '' ),
48 array( 1, 'n not in 1..3', 3, 'in is inclusive' ),
49 array( 0, 'n not in 1..3', 0, '' ),
51 array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ),
52 array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ),
54 array( 0, 'n is not 1 or n is 1', 1, 'or relation' ),
55 array( 1, 'n is 1 or n is 2', 3, 'or relation' ),
57 array( 0, 'n is 1', 1, 'extra whitespace' ),
59 array( 0, 'n mod 3 is 1', 7, 'mod' ),
60 array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ),
62 array( 0, 'n within 1..3', 2, 'within with integer' ),
63 array( 0, 'n within 1..3', 2.5, 'within with float' ),
64 array( 0, 'n in 1..3', 2, 'in with integer' ),
65 array( 1, 'n in 1..3', 2.5, 'in with float' ),
67 array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ),
68 array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ),
70 array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ),
71 array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ),
73 array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ),
74 array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ),
75 array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ),
76 array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ),
78 array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ),
79 array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ),
80 array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ),
81 array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ),
83 array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ),
86 return $tests;
89 function invalidTestCases() {
90 $tests = array(
91 array( 'n mod mod 5 is 1', 'mod mod' ),
92 array( 'n', 'just n' ),
93 array( 'n is in 5', 'is in' ),
96 return $tests;