diff options
author | Bruce Wells <brucekwells@gmail.com> | 2019-01-16 04:04:16 +0300 |
---|---|---|
committer | Bruce Wells <brucekwells@gmail.com> | 2019-01-16 04:04:16 +0300 |
commit | 47df3edbb6c437a049deee356db84f58edcba681 (patch) | |
tree | 866692bf5b60b9523e3b9b271fdb71f9fd890edf /tests | |
parent | 265cff175eb1c0be4b59d937286059532361820f (diff) |
Fixed comma operator
Added unit tests for expressions in function arguments.
Changed array_push to $var[] = native code.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MathTest.php | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php index 81f0230..5bb2ec0 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -135,17 +135,17 @@ class MathTest extends \PHPUnit_Framework_TestCase } public function testFunctionParameterOrder() - { - $calculator = new MathExecutor(); - - $calculator->addFunction('concat', function ($arg1, $arg2) - { - return $arg1.$arg2; - } - ); - $this->assertEquals('testing', $calculator->execute('concat("test","ing")')); - $this->assertEquals('testing', $calculator->execute("concat('test','ing')")); - } + { + $calculator = new MathExecutor(); + + $calculator->addFunction('concat', function ($arg1, $arg2) + { + return $arg1.$arg2; + } + ); + $this->assertEquals('testing', $calculator->execute('concat("test","ing")')); + $this->assertEquals('testing', $calculator->execute("concat('test','ing')")); + } public function testFunction() { @@ -154,17 +154,33 @@ class MathTest extends \PHPUnit_Framework_TestCase $this->assertEquals(round(100/30), $calculator->execute('round(100/30)')); } + public function testEvaluateFunctionParameters() + { + $calculator = new MathExecutor(); + $calculator->addFunction('round', function ($value, $decimals) + { + return round($value, $decimals); + } + ); + $expression = 'round(100 * 1.111111, 2)'; + eval('$phpResult = ' . $expression . ';'); + $this->assertEquals($phpResult, $calculator->execute($expression)); + $expression = 'round((100*0.04)+(((100*1.02)+0.5)*1.28),2)'; + eval('$phpResult = ' . $expression . ';'); + $this->assertEquals($phpResult, $calculator->execute($expression)); + } + public function testQuotes() { $calculator = new MathExecutor(); $testString = "some, long. arg; with: different-separators!"; $calculator->addFunction('test', function ($arg) use ($testString) - { - $this->assertEquals($testString, $arg); + { + $this->assertEquals($testString, $arg); return 0; - } - ); + } + ); $calculator->execute('test("' . $testString . '")'); // single quotes $calculator->execute("test('" . $testString . "')"); // double quotes } -}
\ No newline at end of file +} |