Exemple #1
0
 public function testInvalidExpressions()
 {
     $Eval = new EvalMath();
     $Eval->suppress_errors = true;
     $result = $Eval->evaluate('()');
     $this->assertEqual($Eval->getLastError(), 'Unexpected \')\'');
     $result = $Eval->evaluate('1)');
     $this->assertEqual($Eval->getLastError(), 'Unexpected \')\'');
     $result = $Eval->evaluate('((');
     $this->assertEqual($Eval->getLastError(), 'Expecting \')\'');
     $result = $Eval->evaluate('2+3+');
     $this->assertEqual($Eval->getLastError(), 'Operator \'+\' lacks operand');
     $Eval->suppress_errors = false;
     $this->expectError('Unexpected \',\'');
     $result = $Eval->evaluate('a(1,2');
     $this->assertEqual($Eval->getLastError(), 'Unexpected \',\'');
     $this->assertIdentical(false, $result);
     $this->expectError('Illegal character \'#\'');
     $result = $Eval->evaluate('#');
     $this->assertEqual($Eval->getLastError(), 'Illegal character \'#\'');
     $this->assertIdentical(false, $result);
     $this->expectError('Wrong number of arguments (3 given, 2 expected)');
     $Eval->evaluate('f(x,y) = x+y');
     $result = $Eval->evaluate('f(2,3,4)');
     $this->assertEqual($Eval->getLastError(), 'Wrong number of arguments (3 given, 2 expected)');
     $this->assertIdentical(false, $result);
     $this->expectError('Too many arguments (2 given, 1 expected)');
     $result = $Eval->evaluate('log(2,1)');
     $this->assertEqual($Eval->getLastError(), 'Too many arguments (2 given, 1 expected)');
     $this->assertIdentical(false, $result);
     $this->expectError('Undefined variable \'z\' in function definition');
     $result = $Eval->evaluate('f(x,y) = x+y+z');
     $this->assertEqual($Eval->getLastError(), 'Undefined variable \'z\' in function definition');
     $this->assertIdentical(false, $result);
     unset($Eval);
 }