2022-10-20 19:07:58 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC;
|
2022-10-20 19:07:58 +00:00
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\TexVC;
|
2022-10-20 19:07:58 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\TexVC
|
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Parser
|
2024-02-18 19:06:53 +00:00
|
|
|
*
|
2022-10-20 19:07:58 +00:00
|
|
|
* @group Stub
|
|
|
|
*/
|
|
|
|
class ChemRegressionTest extends MediaWikiUnitTestCase {
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var TexVC */
|
2022-10-20 19:07:58 +00:00
|
|
|
private $texVC;
|
2024-02-18 19:06:53 +00:00
|
|
|
private const CHUNK_SIZE = 100;
|
|
|
|
|
|
|
|
private const FILEPATH = __DIR__ . '/chem-regression.json';
|
|
|
|
|
|
|
|
public static function setUpBeforeClass(): void {
|
|
|
|
if ( !file_exists( self::FILEPATH ) ) {
|
|
|
|
self::markTestSkipped( 'No test file found at specified path: ' . self::FILEPATH );
|
|
|
|
}
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
2022-10-20 19:07:58 +00:00
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->texVC = new TexVC();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the json file to an object
|
|
|
|
* @return array json with testcases
|
|
|
|
*/
|
2024-02-18 19:06:53 +00:00
|
|
|
private function getJSON(): array {
|
|
|
|
$file = file_get_contents( self::FILEPATH );
|
|
|
|
return json_decode( $file, true );
|
2022-10-20 19:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function mkgroups( $arr, $n ) {
|
|
|
|
$result = [];
|
|
|
|
$group = [];
|
|
|
|
$seen = [];
|
|
|
|
foreach ( $arr as $elem ) {
|
|
|
|
if ( array_key_exists( $elem["input"], $seen ) ) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$seen[$elem["input"]] = true;
|
|
|
|
}
|
|
|
|
array_push( $group, $elem );
|
|
|
|
if ( count( $group ) >= $n ) {
|
|
|
|
array_push( $result, $group );
|
|
|
|
$group = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count( $group ) > 0 ) {
|
|
|
|
array_push( $result, $group );
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAllChemRegression() {
|
|
|
|
$texVC = new TexVC();
|
2024-02-18 19:06:53 +00:00
|
|
|
$groups = $this->mkgroups( $this->getJSON(), self::CHUNK_SIZE );
|
2022-10-20 19:07:58 +00:00
|
|
|
foreach ( $groups as $group ) {
|
|
|
|
foreach ( $group as $testcase ) {
|
|
|
|
$testHash = $testcase["inputhash"];
|
|
|
|
$f = $testcase["input"];
|
|
|
|
$type = $testcase["type"];
|
|
|
|
try {
|
|
|
|
$options = [
|
|
|
|
"debug" => false,
|
|
|
|
"usemathrm" => false,
|
|
|
|
"oldtexvc" => false
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( $type === "chem" ) {
|
|
|
|
$options["usemhchem"] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $texVC->check( $testcase["input"], $options );
|
|
|
|
$this->assertEquals( '+', $result["status"], $testHash . " with input: " . $f );
|
|
|
|
} catch ( PhpPegJs\SyntaxError $ex ) {
|
|
|
|
$message = "Syntax error: " . $ex->getMessage() .
|
|
|
|
' at line ' . $ex->grammarLine . ' column ' .
|
|
|
|
$ex->grammarColumn . ' offset ' . $ex->grammarOffset;
|
|
|
|
|
2024-03-10 20:59:19 +00:00
|
|
|
$this->assertTrue( false, $message );
|
2022-10-20 19:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|