diff options
author | Bruce Wells <bruce.wells@simparel.com> | 2018-10-24 21:16:11 +0300 |
---|---|---|
committer | Bruce Wells <bruce.wells@simparel.com> | 2018-10-24 23:01:01 +0300 |
commit | b9f72a001bca4772a003248595ad20b13a5b2277 (patch) | |
tree | bf38dac0f68746efbf5adf31e3a7e94b56bc7db0 /tests | |
parent | 12d41b160bbf8c26601819fcc1f7628c48bc7a00 (diff) |
Additional validation for bad expressions (*+ for example)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MathTest.php | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php index db6e486..df073b2 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,25 @@ 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); + $this->expectException(DivisionByZeroException::class); + $calculator->execute('1 / 0'); } public function testExponentiation() |