Ejemplo n.º 1
0
 /**
  * Print a NumberNode.
  *
  * @param NumerNode $node
  */
 public function visitNumberNode(NumberNode $node)
 {
     $val = $node->getValue();
     return "{$val}:float";
 }
Ejemplo n.º 2
0
 /**
  * Evaluate a NumberNode
  *
  * Retuns the value of an NumberNode
  *
  * @param NumberNode $node AST to be evaluated
  * @retval float
  */
 public function visitNumberNode(NumberNode $node)
 {
     return Complex::create($node->getValue(), 0);
 }
Ejemplo n.º 3
0
 /**
  * Evaluate a NumberNode
  *
  * Retuns the value of an NumberNode
  *
  * @param NumberNode $node AST to be evaluated
  * @retval float
  */
 public function visitNumberNode(NumberNode $node)
 {
     return $node->getValue();
 }
Ejemplo n.º 4
0
 public function testCanComputeComplexity()
 {
     $node = new NumberNode(1);
     $this->assertEquals($node->complexity(), 2);
     $node = new IntegerNode(1);
     $this->assertEquals($node->complexity(), 1);
     $node = new RationalNode(1, 2);
     $this->assertEquals($node->complexity(), 2);
     $node = new VariableNode('x');
     $this->assertEquals($node->complexity(), 1);
     $node = new ConstantNode('pi');
     $this->assertEquals($node->complexity(), 1);
     $f = $this->parser->parse('x+y');
     $this->assertEquals($f->complexity(), 4);
     $f = $this->parser->parse('x-y');
     $this->assertEquals($f->complexity(), 4);
     $f = $this->parser->parse('x*y');
     $this->assertEquals($f->complexity(), 4);
     $f = $this->parser->parse('x/y');
     $this->assertEquals($f->complexity(), 6);
     $f = $this->parser->parse('x^y');
     $this->assertEquals($f->complexity(), 10);
     $f = $this->parser->parse('sin(x)');
     $this->assertEquals($f->complexity(), 6);
     $f = $this->parser->parse('x + sin(x^2)');
     $this->assertEquals($f->complexity(), 18);
     $node = new SubExpressionNode('(');
     $this->assertEquals($node->complexity(), 1000);
 }