From b9f72a001bca4772a003248595ad20b13a5b2277 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Wed, 24 Oct 2018 14:16:11 -0400 Subject: Additional validation for bad expressions (*+ for example) --- tests/MathTest.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests/MathTest.php') 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() -- cgit v1.2.3