mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Expand texvcjs comparison test
* Currently the regression test only tests if all formulae that passed the test before still pass the test * This change also compares the output Change-Id: Ib667de2e7e512cf7d045e28a19c6a5f7d994dfc6
This commit is contained in:
parent
efc93cb5e9
commit
0aecf2ab10
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ composer.lock
|
|||
/tests/selenium/log
|
||||
en-wiki-formulae.json
|
||||
en-wiki-formulae-good.json
|
||||
en-wiki-formulae-good-reference.json
|
||||
chem-regression.json
|
||||
# Editors
|
||||
*.kate-swp
|
||||
|
|
|
@ -15,3 +15,8 @@ curl $URL -o $FILEPATH
|
|||
FILEPATH=../tests/phpunit/unit/TexVC/chem-regression.json
|
||||
URL=https://raw.githubusercontent.com/wikimedia/mediawiki-services-texvcjs/fb56991251b8889b554fc42ef9fe4825bc35d0ed/test/chem-regression.json
|
||||
curl $URL -o $FILEPATH
|
||||
|
||||
# Downloads the file containing reference renderings for all english wikipedia chem-regression tests to the testfolder
|
||||
FILEPATH=../tests/phpunit/unit/TexVC/en-wiki-formulae-good-reference.json
|
||||
URL=https://zenodo.org/record/7494266/files/normalized.json?download=1
|
||||
curl $URL -o $FILEPATH
|
||||
|
|
|
@ -18,15 +18,16 @@ use MediaWikiUnitTestCase;
|
|||
class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
||||
private $ACTIVE = true; # indicate whether this test is active
|
||||
private $FILENAME = "en-wiki-formulae-good.json";
|
||||
private $REF_FILENAME = "en-wiki-formulae-good-reference.json";
|
||||
private $CHUNKSIZE = 1000;
|
||||
|
||||
/**
|
||||
* Reads the json file to an object
|
||||
* @throws InvalidArgumentException File with testcases does not exists.
|
||||
* @param string $filePath file to be read
|
||||
* @throws InvalidArgumentException File with testcases does not exist.
|
||||
* @return array json with testcases
|
||||
*/
|
||||
private function getJSON() {
|
||||
$filePath = __DIR__ . '/' . $this->FILENAME;
|
||||
private function getJSON( $filePath ): array {
|
||||
if ( !file_exists( $filePath ) ) {
|
||||
throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath );
|
||||
}
|
||||
|
@ -35,26 +36,21 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
|||
return $json;
|
||||
}
|
||||
|
||||
private static function mkgroups( $arr, $n ) {
|
||||
$result = [];
|
||||
public function provideTestCases(): \Generator {
|
||||
$group = [];
|
||||
$groupNo = 1;
|
||||
foreach ( $arr as $key => $elem ) {
|
||||
$group[$key] = $elem;
|
||||
if ( count( $group ) >= $n ) {
|
||||
$result["Group $groupNo"] = [ $group ];
|
||||
$references = $this->getJSON( __DIR__ . '/' . $this->REF_FILENAME );
|
||||
foreach ( $this->getJSON( __DIR__ . '/' . $this->FILENAME ) as $key => $elem ) {
|
||||
$group[$key] = [ $elem , $references[ $key ] ];
|
||||
if ( count( $group ) >= $this->CHUNKSIZE ) {
|
||||
yield "Group $groupNo" => [ $group ];
|
||||
$groupNo++;
|
||||
$group = [];
|
||||
}
|
||||
}
|
||||
if ( count( $group ) > 0 ) {
|
||||
$result["Group $groupNo"] = [ $group ];
|
||||
yield "Group $groupNo" => [ $group ];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function provideTestCases(): array {
|
||||
return self::mkgroups( $this->getJSON(), $this->CHUNKSIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +63,7 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
|||
|
||||
$texVC = new TexVC();
|
||||
|
||||
foreach ( $testcase as $hash => $tex ) {
|
||||
foreach ( $testcase as $hash => [ $tex, $ref ] ) {
|
||||
try {
|
||||
$result = $texVC->check( $tex, [
|
||||
"debug" => false,
|
||||
|
@ -75,8 +71,18 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
|||
"oldtexvc" => false
|
||||
] );
|
||||
|
||||
$good = ( $result["status"] === '+' );
|
||||
$this->assertTrue( $good, $hash . " with input: " . $tex );
|
||||
$this->assertEquals( '+', $result["status"],
|
||||
$hash . " failed. Input: " . $tex );
|
||||
if ( preg_match( '/\\\\definecolor \{/m', $ref ) ) {
|
||||
// crop long numbers in color codes from 16 to 14 digits
|
||||
// while this heuristic might produce false positivies in general, it is sufficient
|
||||
// for this dataset
|
||||
$ref = preg_replace( '/(0.\d{14})\d{2}([,\}])/m', '$1$2', $ref );
|
||||
}
|
||||
|
||||
$this->assertEquals( $ref, $result["output"],
|
||||
$hash . " does not match reference." );
|
||||
|
||||
$r1 = $texVC->check( $result["output"] );
|
||||
$this->assertEquals( "+", $r1["status"],
|
||||
"error rechecking output: " . $tex . " -> " . $result["output"] );
|
||||
|
|
Loading…
Reference in a new issue