aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php42
1 files changed, 39 insertions, 3 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index db6e486..c8b8a03 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -11,7 +11,15 @@
namespace NXP\Tests;
-use \NXP\MathExecutor;
+use NXP\MathExecutor;
+use NXP\Exception\DivisionByZeroException;
+use NXP\Exception\IncorrectBracketsException;
+use NXP\Exception\IncorrectExpressionException;
+use NXP\Exception\MathExecutorException;
+use NXP\Exception\UnknownFunctionException;
+use NXP\Exception\UnknownOperatorException;
+use NXP\Exception\UnknownTokenException;
+use NXP\Exception\UnknownVariableException;
class MathTest extends \PHPUnit_Framework_TestCase
{
@@ -27,10 +35,28 @@ class MathTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($calculator->execute($expression), $phpResult);
}
+ public function testUnknownFunctionException()
+ {
+ $calculator = new MathExecutor();
+ $this->expectException(UnknownFunctionException::class);
+ $calculator->execute('1 * fred("wilma") + 3');
+ }
+
+ public function testIncorrectExpressionException()
+ {
+ $calculator = new MathExecutor();
+ $this->expectException(IncorrectExpressionException::class);
+ $calculator->execute('1 * + ');
+ }
+
public function testZeroDivision()
{
$calculator = new MathExecutor();
$this->assertEquals($calculator->execute('1 / 0'), 0);
+
+ // future version with allow for optional exceptions on divide by zero
+ // $this->expectException(DivisionByZeroException::class);
+ // $calculator->execute('1 / 0');
}
public function testExponentiation()
@@ -63,15 +89,25 @@ class MathTest extends \PHPUnit_Framework_TestCase
['(5 + 3) * -1'],
- ['2+2*2'],
+ ['2- 2*2'],
+ ['2-(2*2)'],
+ ['(2- 2)*2'],
+ ['2 + 2*2'],
+ ['2+ 2*2'],
['(2+2)*2'],
- ['(2+2)*-2'],
+ ['(2 + 2)*-2'],
['(2+-2)*2'],
['sin(10) * cos(50) / min(10, 20/2)'],
['100500 * 3.5E5'],
['100500 * 3.5E-5'],
+
+ ['-1 + -2'],
+ ['-1+-2'],
+ ['-1- -2'],
+ ['-1/-2'],
+ ['-1*-2'],
];
}