diff options
author | Bruce Wells <bruce.wells@simparel.com> | 2018-10-30 23:16:01 +0300 |
---|---|---|
committer | Bruce Wells <bruce.wells@simparel.com> | 2018-10-31 16:35:40 +0300 |
commit | f0d4562b9ef3bbc64cb8353f0597e639420ede6b (patch) | |
tree | 86f215d0c7187843e863e7a980ae81943e7d4a5f /tests/MathTest.php | |
parent | 334dd26e3c78a36002aed34aa26aa526b11c5dfb (diff) |
Division By Zero Exception support
Updated the documentation.
Unit tests for strings.
DivisionByZeroException support.
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r-- | tests/MathTest.php | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php index c8b8a03..c5dd60d 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -35,36 +35,6 @@ 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() - { - $calculator = new MathExecutor(); - $this->assertEquals($calculator->execute('10 ^ 2'), 100); - } - /** * Expressions data provider */ @@ -94,6 +64,7 @@ class MathTest extends \PHPUnit_Framework_TestCase ['(2- 2)*2'], ['2 + 2*2'], ['2+ 2*2'], + ['2+2*2'], ['(2+2)*2'], ['(2 + 2)*-2'], ['(2+-2)*2'], @@ -103,6 +74,10 @@ class MathTest extends \PHPUnit_Framework_TestCase ['100500 * 3.5E5'], ['100500 * 3.5E-5'], + ['1 + "2" / 3'], + ["1.5 + '2.5' / 4"], + ['1.5 + "2.5" * ".5"'], + ['-1 + -2'], ['-1+-2'], ['-1- -2'], @@ -111,6 +86,40 @@ class MathTest extends \PHPUnit_Framework_TestCase ]; } + 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('10 / 0'), 0); + } + + public function testZeroDivisionException() + { + $calculator = new MathExecutor(); + $calculator->setDivisionByZeroException(); + $this->expectException(DivisionByZeroException::class); + $calculator->execute('10 / 0'); + } + + public function testExponentiation() + { + $calculator = new MathExecutor(); + $this->assertEquals($calculator->execute('10 ^ 2'), 100); + } + public function testFunction() { $calculator = new MathExecutor(); |