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 __construct($node, $parent) { parent::__construct($node, $parent); self::$possible_attributes = array_merge(parent::$possible_attributes, self::$possible_attributes); self::$required_attributes = array_merge(parent::$required_attributes, self::$required_attributes); self::$possible_children = array_merge(parent::$possible_children, self::$possible_children); self::$required_children = array_merge(parent::$required_children, self::$required_children); }
public function apply() { return $this->_a + $this->_b; } } class Divide extends Computation { public function apply() { return $this->_a / $this->_b; } } $add = new Add(5, 5); println($add->apply()); //->10 $divide = new Divide(5, 5); println($divide->apply()); //->1 function apply(callable $operator) { return function ($a, $b) use($operator) { return $operator($a, $b); }; } $add = function ($a, $b) { return $a + $b; }; $divide = function ($a, $b) { return $a / $b; }; apply($add)(5, 5);