MediaWiki  1.30.0
ExpressionTest.php
Go to the documentation of this file.
1 <?php
3 
7  protected $parser;
8 
9  protected function setUp() {
10  parent::setUp();
11  $this->parser = new ExprParser();
12  }
13 
17  function testExpression( $input, $expected ) {
18  $this->assertEquals(
19  $expected,
20  $this->parser->doExpression( $input )
21  );
22  }
23 
24  function provideExpressions() {
25  return [
26  [ '1 or 0', '1' ],
27  [ 'not (1 and 0)', '1' ],
28  [ 'not 0', '1' ],
29  [ '4 < 5', '1' ],
30  [ '-5 < 2', '1' ],
31  [ '-2 <= -2', '1' ],
32  [ '4 > 3', '1' ],
33  [ '4 > -3', '1' ],
34  [ '5 >= 2', '1' ],
35  [ '2 >= 2', '1' ],
36  [ '1 != 2', '1' ],
37  [ '-4 * -4 = 4 * 4', '1' ],
38  [ 'not (1 != 1)', '1' ],
39  [ '1 + 1', '2' ],
40  [ '-1 + 1', '0' ],
41  [ '+1 + 1', '2' ],
42  [ '4 * 4', '16' ],
43  [ '(1/3) * 3', '1' ],
44  [ '3 / 1.5', '2' ],
45  [ '3 / 0.2', '15' ],
46  [ '3 / ( 2.0 * 0.1 )', '15' ],
47  [ '3 / ( 2.0 / 10 )', '15' ],
48  [ '3 / (- 0.2 )', '-15' ],
49  [ '3 / abs( 0.2 )', '15' ],
50  [ '3 mod 2', '1' ],
51  [ '1e4', '10000' ],
52  [ '1e-2', '0.01' ],
53  [ '4.0 round 0', '4' ],
54  [ 'ceil 4', '4' ],
55  [ 'floor 4', '4' ],
56  [ '4.5 round 0', '5' ],
57  [ '4.2 round 0', '4' ],
58  [ '-4.2 round 0', '-4' ],
59  [ '-4.5 round 0', '-5' ],
60  [ '-2.0 round 0', '-2' ],
61  [ 'ceil -3', '-3' ],
62  [ 'floor -6.0', '-6' ],
63  [ 'ceil 4.2', '5' ],
64  [ 'ceil -4.5', '-4' ],
65  [ 'floor -4.5', '-5' ],
66  [ 'abs(-2)', '2' ],
67  [ 'ln(exp(1))', '1' ],
68  [ 'trunc(4.5)', '4' ],
69  [ 'trunc(-4.5)', '-4' ],
70  [ '123 fmod (2^64-1)', '123' ],
71  [ '5.7 mod 1.3', '0' ],
72  [ '5.7 fmod 1.3', '0.5' ],
73  ];
74  }
75 }
ExpressionTest
Definition: ExpressionTest.php:2
ExpressionTest\provideExpressions
provideExpressions()
Definition: ExpressionTest.php:24
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ExpressionTest\testExpression
testExpression( $input, $expected)
provideExpressions
Definition: ExpressionTest.php:17
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
some
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for some
Definition: design.txt:79
ExprParser
Definition: Expr.php:69
captcha-old.p
p
Definition: captcha-old.py:275
ExpressionTest\$parser
ExprParser $parser
Definition: ExpressionTest.php:7
ExpressionTest\setUp
setUp()
Definition: ExpressionTest.php:9
captcha-old.parser
parser
Definition: captcha-old.py:210