2022-09-05 12:33:12 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-09-05 12:33:12 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
|
|
|
use InvalidArgumentException;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Matrix;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
2022-09-05 12:33:12 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Matrix
|
2022-09-05 12:33:12 +00:00
|
|
|
*/
|
|
|
|
class MatrixTest extends MediaWikiUnitTestCase {
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var Matrix */
|
2022-09-05 12:33:12 +00:00
|
|
|
private $sampleMatrix;
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->sampleMatrix = new Matrix( 'align',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmptyMatrix() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Matrix();
|
|
|
|
throw new TypeError( 'Should not create an empty matrix' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNestedArguments() {
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
new Matrix(
|
|
|
|
'align',
|
|
|
|
new TexArray(
|
|
|
|
new Literal( 'a' ) ) );
|
|
|
|
throw new TypeError( 'Nested arguments have to be type of TexArray' );
|
|
|
|
}
|
|
|
|
|
2024-04-12 15:43:24 +00:00
|
|
|
public function testInstanceOfTexArray() {
|
|
|
|
$this->assertEquals( 'MediaWiki\\Extension\\Math\\WikiTexVC\\Nodes\\TexArray',
|
2023-03-11 21:01:39 +00:00
|
|
|
get_parent_class( $this->sampleMatrix ),
|
2024-04-12 15:43:24 +00:00
|
|
|
'Should create an instance of TexArray' );
|
2022-09-05 12:33:12 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$this->assertNotEmpty( $this->sampleMatrix->getTop() );
|
|
|
|
$this->assertNotEmpty( $this->sampleMatrix->getMainarg() );
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:33:12 +00:00
|
|
|
public function testRenderMatrix() {
|
|
|
|
$this->assertEquals( '{\\begin{align}a\\end{align}}', $this->sampleMatrix->render() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractCurlies() {
|
|
|
|
$this->assertEquals( '{\\begin{align}a\\end{align}}', $this->sampleMatrix->inCurlies(),
|
|
|
|
'Should not create extra curlies' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifiers() {
|
|
|
|
$this->assertEquals( [ 'a' ], $this->sampleMatrix->extractIdentifiers(),
|
|
|
|
'Should extract identifiers' );
|
|
|
|
}
|
2024-04-12 15:43:24 +00:00
|
|
|
|
|
|
|
public function testCreateFromMatrix() {
|
|
|
|
$matrix = new Matrix( 'align',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ) ) );
|
|
|
|
$newMatrix = new Matrix( 'align', $matrix );
|
|
|
|
$this->assertEquals( $matrix, $newMatrix,
|
|
|
|
'Should create a matrix from a matrix' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContainsTop() {
|
|
|
|
$matrix = new Matrix( 'top',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ) ) );
|
|
|
|
$this->assertTrue( $matrix->containsFunc( '\\begin{top}' ),
|
|
|
|
'Should create top attribute' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContainsArgs() {
|
|
|
|
$matrix = new Matrix( 'top',
|
|
|
|
new TexArray( new TexArray( new Literal( '\\sin' ) ) ) );
|
|
|
|
$this->assertTrue( $matrix->containsFunc( '\\sin' ),
|
|
|
|
'Should contain inner elements' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenderMML() {
|
|
|
|
$matrix = new Matrix( 'matrix',
|
|
|
|
new TexArray( new TexArray( new Literal( '\\sin' ) ) ) );
|
|
|
|
$this->assertStringContainsString( 'mtable', $matrix->renderMML(),
|
|
|
|
'Should render a matrix' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTop() {
|
|
|
|
$this->sampleMatrix->setTop( 'abc' );
|
|
|
|
$this->assertEquals( 'abc', $this->sampleMatrix->getTop() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testColSpec() {
|
|
|
|
$this->sampleMatrix->setColumnSpecs( TexArray::newCurly( new Literal( '2' ) ) );
|
|
|
|
$this->assertEquals( '{2}', $this->sampleMatrix->getColumnSpecs()->render() );
|
|
|
|
}
|
2022-09-05 12:33:12 +00:00
|
|
|
}
|