aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
authorBruce Wells <phpfui@users.noreply.github.com>2018-09-12 21:21:25 +0300
committerGitHub <noreply@github.com>2018-09-12 21:21:25 +0300
commit12d41b160bbf8c26601819fcc1f7628c48bc7a00 (patch)
treec50b777d06d9e9eeff6aeb59005c389ddf9a552b /tests/MathTest.php
parent855ca5dfc1a6d70d9872df4b0d7bea8ba3c4c040 (diff)
parent4a672cfd94c07e1821227f27fd1edd2217685136 (diff)
Merge pull request #1 from NeonXP/master
Merge from upstream master
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php54
1 files changed, 32 insertions, 22 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index a83a0d4..db6e486 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -27,7 +27,7 @@ class MathTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($calculator->execute($expression), $phpResult);
}
- public function testZeroDevision()
+ public function testZeroDivision()
{
$calculator = new MathExecutor();
$this->assertEquals($calculator->execute('1 / 0'), 0);
@@ -44,34 +44,44 @@ class MathTest extends \PHPUnit_Framework_TestCase
*/
public function providerExpressions()
{
- return array(
- array('0.1 + 0.2'),
- array('1 + 2'),
+ return [
+ ['0.1 + 0.2'],
+ ['1 + 2'],
- array('0.1 - 0.2'),
- array('1 - 2'),
+ ['0.1 - 0.2'],
+ ['1 - 2'],
- array('0.1 * 2'),
- array('1 * 2'),
+ ['0.1 * 2'],
+ ['1 * 2'],
- array('0.1 / 0.2'),
- array('1 / 2'),
+ ['0.1 / 0.2'],
+ ['1 / 2'],
- array('2 * 2 + 3 * 3'),
+ ['2 * 2 + 3 * 3'],
- array('1 + 0.6 - 3 * 2 / 50'),
+ ['1 + 0.6 - 3 * 2 / 50'],
- array('(5 + 3) * -1'),
+ ['(5 + 3) * -1'],
- array('2+2*2'),
- array('(2+2)*2'),
- array('(2+2)*-2'),
- array('(2+-2)*2'),
+ ['2+2*2'],
+ ['(2+2)*2'],
+ ['(2+2)*-2'],
+ ['(2+-2)*2'],
- array('sin(10) * cos(50) / min(10, 20/2)'),
+ ['sin(10) * cos(50) / min(10, 20/2)'],
- array('100500 * 3.5E5'),
- array('100500 * 3.5E-5')
- );
+ ['100500 * 3.5E5'],
+ ['100500 * 3.5E-5'],
+ ];
}
-}
+
+ public function testFunction()
+ {
+ $calculator = new MathExecutor();
+
+ $calculator->addFunction('round', function ($arg) { return round($arg); }, 1);
+ /** @var float $phpResult */
+ eval('$phpResult = round(100/30);');
+ $this->assertEquals($calculator->execute('round(100/30)'), $phpResult);
+ }
+} \ No newline at end of file