function CtoolsMathExpressionTestCase::testBuildInFunctions
Test various built-in transcendental and extended functions.
File
-
tests/
math_expression.test, line 183
Class
- CtoolsMathExpressionTestCase
- Tests the MathExpression library of ctools.
Code
public function testBuildInFunctions() {
$math_expr = new ctools_math_expr();
foreach (range(1, 4) as $n) {
$random_double = $this->rand01();
$random_int = mt_rand(-65535, 65535);
$this->assertFloat(sin($random_double), $math_expr->evaluate("sin({$random_double})"), "sin({$random_double})");
$this->assertFloat(cos($random_double), $math_expr->evaluate("cos({$random_double})"), "cos({$random_double})");
$this->assertFloat(tan($random_double), $math_expr->evaluate("tan({$random_double})"), "tan({$random_double})");
$this->assertFloat(exp($random_double), $math_expr->evaluate("exp({$random_double})"), "exp({$random_double})");
$this->assertFloat(sqrt($random_double), $math_expr->evaluate("sqrt({$random_double})"), "sqrt({$random_double})");
$this->assertFloat(log($random_double), $math_expr->evaluate("ln({$random_double})"), "ln({$random_double})");
$this->assertFloat(round($random_double), $math_expr->evaluate("round({$random_double})"), "round({$random_double})");
$random_real = $random_double + $random_int;
$this->assertFloat(abs($random_real), $math_expr->evaluate('abs(' . $random_real . ')'), "abs({$random_real})");
$this->assertEqual(round($random_real), $math_expr->evaluate('round(' . $random_real . ')'), "round({$random_real})");
$this->assertEqual(ceil($random_real), $math_expr->evaluate('ceil(' . $random_real . ')'), "ceil({$random_real})");
$this->assertEqual(floor($random_real), $math_expr->evaluate('floor(' . $random_real . ')'), "floor({$random_real})");
}
$this->assertFloat(time(), $math_expr->evaluate('time()'), "time()");
$random_double_a = $this->rand01();
$random_double_b = $this->rand01();
$this->assertFloat(max($random_double_a, $random_double_b), $math_expr->evaluate("max({$random_double_a}, {$random_double_b})"), "max({$random_double_a}, {$random_double_b})");
$this->assertFloat(min($random_double_a, $random_double_b), $math_expr->evaluate("min({$random_double_a}, {$random_double_b})"), "min({$random_double_a}, {$random_double_b})");
}