Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
fixed subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Mar 30, 2016
1 parent 50b884c commit 351fb35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Deimos/Expressions/Subtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class Subtraction extends Addition
public function operate(\SplStack $stack)
{
$left = $stack->pop()->operate($stack);
$right = $stack->pop()->operate($stack);
$right = 0;
if ($stack->count()) {
$right = $stack->pop()->operate($stack);
}
return $right - $left;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Deimos/MathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function testExampleSub()
{
$math = new Math();
$this->assertEquals($math->evaluate('2 -3 '), -1);
$this->assertEquals($math->evaluate('-2 -3 '), -5);
}

public function testExampleMul()
Expand Down Expand Up @@ -45,6 +46,7 @@ public function testExampleNumber()
{
$math = new Math();
$this->assertEquals($math->evaluate('77777'), 77777);
$this->assertEquals($math->evaluate('-77777'), -77777);
}

public function testExampleParenthesis()
Expand Down

0 comments on commit 351fb35

Please sign in to comment.