aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/NXP/Classes/Token/TokenDivision.php4
-rw-r--r--tests/MathTest.php21
2 files changed, 17 insertions, 8 deletions
diff --git a/src/NXP/Classes/Token/TokenDivision.php b/src/NXP/Classes/Token/TokenDivision.php
index a85bec5..5bbc35e 100644
--- a/src/NXP/Classes/Token/TokenDivision.php
+++ b/src/NXP/Classes/Token/TokenDivision.php
@@ -59,10 +59,6 @@ class TokenDivision extends AbstractOperator
throw new IncorrectExpressionException("Division requires two operators");
}
- if ($op2->getValue() == 0){
- throw new DivisionByZeroException();
- }
-
$result = $op2->getValue() != 0 ? $op1->getValue() / $op2->getValue() : 0;
return new TokenNumber($result);
diff --git a/tests/MathTest.php b/tests/MathTest.php
index df073b2..c8b8a03 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -52,8 +52,11 @@ class MathTest extends \PHPUnit_Framework_TestCase
public function testZeroDivision()
{
$calculator = new MathExecutor();
- $this->expectException(DivisionByZeroException::class);
- $calculator->execute('1 / 0');
+ $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()
@@ -86,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'],
];
}