mediawiki-extensions-Parser.../testExpr.php
Andrew Garrett d9fd747f2d Revert "Adds explicit round-off checking to operations that are sensitive to floating point vs. integer round-off errors.", et al. ( r46683, r46671 )
Reimplement, but better! Use BC Math library where possible, for fixed-point math operations. The tolerance aspect has been included by doing math internally at 16 digits, but discarding the last two digits for the purpose of comparison.
2009-02-12 22:29:32 +00:00

38 lines
912 B
PHP

<?php
require_once ( getenv('MW_INSTALL_PATH') !== false
? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc"
: dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
require( 'Expr.php' );
$tests = file( 'exprTests.txt' );
$pass = $fail = 0;
// Each test is on one line. The test must always evaluate to '1'.
$parser = new ExprParser;
foreach( $tests as $test ) {
$test = trim($test);
if ( in_string( ';', $test ) )
list($input,$expected) = explode(';', $test);
else {
$input = $test;
$expected = 1;
}
$expected = trim($expected);
$input = trim($input);
$result = $parser->doExpression( $input );
if ($result != $expected) {
print
"FAILING test -- $input
gave a final result of $result, instead of $expected.\n";
$fail++;
} else {
print "PASSED test $test\n";
$pass++;
}
}
print "Passed $pass tests, failed $fail tests, out of a total of ".($pass+$fail)."\n";