public final function execute(OperandStack $values)
 {
     $rhs = $values->peek();
     $values->pop();
     $lhs = $values->peek();
     $result = $this->executeImplementation($lhs, $rhs);
     $values->replaceTop($result);
 }
Esempio n. 2
0
 public function execute(OperandStack $values)
 {
     $operand = $values->peek();
     $result = 1;
     while ($operand > 0) {
         $result *= $operand;
         $operand -= 1;
     }
     $values->replaceTop($result);
 }
Esempio n. 3
0
 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());
 }
Esempio n. 4
0
 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());
 }