public final function execute(OperandStack $values) { $rhs = $values->peek(); $values->pop(); $lhs = $values->peek(); $result = $this->executeImplementation($lhs, $rhs); $values->replaceTop($result); }
public function execute(OperandStack $values) { $operand = $values->peek(); $result = 1; while ($operand > 0) { $result *= $operand; $operand -= 1; } $values->replaceTop($result); }
public function testShouldBeAbleToDivide() { $pushvalue = 12; $pushvalue2 = 2; $stack = new OperandStack(); $stack->push($pushvalue); $stack->push($pushvalue2); $op = new Divide(); $op->execute($stack); $this->assertEquals(6, $stack->peek()); }
public function testCanMultiplyTwoNumbers() { $pushvalue = 3; $pushvalue2 = 7; $stack = new OperandStack(); $stack->push($pushvalue); $stack->push($pushvalue2); $op = new Multiply(); $op->execute($stack); $this->assertEquals(21, $stack->peek()); }