aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
authorBruce Wells <phpfui@users.noreply.github.com>2018-10-31 16:51:19 +0300
committerGitHub <noreply@github.com>2018-10-31 16:51:19 +0300
commit07d02e1fb0aeb9fca7174a065f61a5fa2643b12f (patch)
tree86f215d0c7187843e863e7a980ae81943e7d4a5f /tests/MathTest.php
parent43f0ff3f28d198fbb4e36346fc5f36fa91cf3e18 (diff)
parentf0d4562b9ef3bbc64cb8353f0597e639420ede6b (diff)
Merge branch 'master' into master
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php69
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();