mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 23:25:02 +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
|
/tests/selenium/log
|
||||||
en-wiki-formulae.json
|
en-wiki-formulae.json
|
||||||
en-wiki-formulae-good.json
|
en-wiki-formulae-good.json
|
||||||
|
en-wiki-formulae-good-reference.json
|
||||||
chem-regression.json
|
chem-regression.json
|
||||||
# Editors
|
# Editors
|
||||||
*.kate-swp
|
*.kate-swp
|
||||||
|
|
|
@ -15,3 +15,8 @@ curl $URL -o $FILEPATH
|
||||||
FILEPATH=../tests/phpunit/unit/TexVC/chem-regression.json
|
FILEPATH=../tests/phpunit/unit/TexVC/chem-regression.json
|
||||||
URL=https://raw.githubusercontent.com/wikimedia/mediawiki-services-texvcjs/fb56991251b8889b554fc42ef9fe4825bc35d0ed/test/chem-regression.json
|
URL=https://raw.githubusercontent.com/wikimedia/mediawiki-services-texvcjs/fb56991251b8889b554fc42ef9fe4825bc35d0ed/test/chem-regression.json
|
||||||
curl $URL -o $FILEPATH
|
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 {
|
class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
||||||
private $ACTIVE = true; # indicate whether this test is active
|
private $ACTIVE = true; # indicate whether this test is active
|
||||||
private $FILENAME = "en-wiki-formulae-good.json";
|
private $FILENAME = "en-wiki-formulae-good.json";
|
||||||
|
private $REF_FILENAME = "en-wiki-formulae-good-reference.json";
|
||||||
private $CHUNKSIZE = 1000;
|
private $CHUNKSIZE = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the json file to an object
|
* 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
|
* @return array json with testcases
|
||||||
*/
|
*/
|
||||||
private function getJSON() {
|
private function getJSON( $filePath ): array {
|
||||||
$filePath = __DIR__ . '/' . $this->FILENAME;
|
|
||||||
if ( !file_exists( $filePath ) ) {
|
if ( !file_exists( $filePath ) ) {
|
||||||
throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath );
|
throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath );
|
||||||
}
|
}
|
||||||
|
@ -35,26 +36,21 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function mkgroups( $arr, $n ) {
|
public function provideTestCases(): \Generator {
|
||||||
$result = [];
|
|
||||||
$group = [];
|
$group = [];
|
||||||
$groupNo = 1;
|
$groupNo = 1;
|
||||||
foreach ( $arr as $key => $elem ) {
|
$references = $this->getJSON( __DIR__ . '/' . $this->REF_FILENAME );
|
||||||
$group[$key] = $elem;
|
foreach ( $this->getJSON( __DIR__ . '/' . $this->FILENAME ) as $key => $elem ) {
|
||||||
if ( count( $group ) >= $n ) {
|
$group[$key] = [ $elem , $references[ $key ] ];
|
||||||
$result["Group $groupNo"] = [ $group ];
|
if ( count( $group ) >= $this->CHUNKSIZE ) {
|
||||||
|
yield "Group $groupNo" => [ $group ];
|
||||||
$groupNo++;
|
$groupNo++;
|
||||||
$group = [];
|
$group = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( count( $group ) > 0 ) {
|
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();
|
$texVC = new TexVC();
|
||||||
|
|
||||||
foreach ( $testcase as $hash => $tex ) {
|
foreach ( $testcase as $hash => [ $tex, $ref ] ) {
|
||||||
try {
|
try {
|
||||||
$result = $texVC->check( $tex, [
|
$result = $texVC->check( $tex, [
|
||||||
"debug" => false,
|
"debug" => false,
|
||||||
|
@ -75,8 +71,18 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
|
||||||
"oldtexvc" => false
|
"oldtexvc" => false
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$good = ( $result["status"] === '+' );
|
$this->assertEquals( '+', $result["status"],
|
||||||
$this->assertTrue( $good, $hash . " with input: " . $tex );
|
$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"] );
|
$r1 = $texVC->check( $result["output"] );
|
||||||
$this->assertEquals( "+", $r1["status"],
|
$this->assertEquals( "+", $r1["status"],
|
||||||
"error rechecking output: " . $tex . " -> " . $result["output"] );
|
"error rechecking output: " . $tex . " -> " . $result["output"] );
|
||||||
|
|
Loading…
Reference in a new issue