| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes; |
| 4 |
|
| 5 |
use ArgumentCountError; |
| 6 |
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow; |
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\FQ; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal; |
| 9 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray; |
| 10 |
use MediaWikiUnitTestCase; |
| 11 |
use TypeError; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class FQTest extends MediaWikiUnitTestCase { |
| 17 |
|
| 18 |
public function testEmptyFQ() { |
| 19 |
$this->expectException( ArgumentCountError::class ); |
| 20 |
new FQ(); |
| 21 |
throw new ArgumentCountError( 'Should not create an empty fq' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function testOneArgumentFQ() { |
| 25 |
$this->expectException( ArgumentCountError::class ); |
| 26 |
new FQ( new Literal( 'a' ) ); |
| 27 |
throw new ArgumentCountError( 'Should not create a fq with one argument' ); |
| 28 |
} |
| 29 |
|
| 30 |
public function testIncorrectTypeFQ() { |
| 31 |
$this->expectException( TypeError::class ); |
| 32 |
new FQ( 'a', 'b', 'c' ); |
| 33 |
throw new TypeError( 'Should not create a fq with incorrect type' ); |
| 34 |
} |
| 35 |
|
| 36 |
public function testBasicFQ() { |
| 37 |
$fq = new FQ( new Literal( 'a' ), new Literal( 'b' ), new Literal( 'c' ) ); |
| 38 |
$this->assertEquals( 'a_{b}^{c}', $fq->render(), 'Should create a basic fq' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function testGetters() { |
| 42 |
$fq = new FQ( new Literal( 'a' ), new Literal( 'b' ), new Literal( 'c' ) ); |
| 43 |
$this->assertNotEmpty( $fq->getBase() ); |
| 44 |
$this->assertNotEmpty( $fq->getUp() ); |
| 45 |
$this->assertNotEmpty( $fq->getDown() ); |
| 46 |
} |
| 47 |
|
| 48 |
public function testRenderEmptyFq() { |
| 49 |
$fq = new FQ( TexArray::newCurly(), new Literal( 'b' ), new Literal( 'c' ) ); |
| 50 |
$result = $fq->renderMML(); |
| 51 |
$this->assertStringContainsString( 'msubsup', $result ); |
| 52 |
$this->assertStringContainsString( ( new MMLmrow() )->getEmpty(), $result ); |
| 53 |
} |
| 54 |
|
| 55 |
public function testLatin() { |
| 56 |
$fq = new FQ( new Literal( 'a' ), new Literal( 'b' ), new Literal( 'c' ) ); |
| 57 |
$this->assertStringContainsString( 'msubsup', $fq->renderMML() ); |
| 58 |
} |
| 59 |
|
| 60 |
public function testSum() { |
| 61 |
$fq = new FQ( new Literal( '\sum' ), new Literal( 'b' ), new Literal( 'c' ) ); |
| 62 |
$this->assertStringContainsString( 'munderover', $fq->renderMML() ); |
| 63 |
} |
| 64 |
|
| 65 |
public function testGreek() { |
| 66 |
$fq = new FQ( new Literal( '\\alpha' ), new Literal( 'b' ), new Literal( 'c' ) ); |
| 67 |
$this->assertStringContainsString( 'msubsup', $fq->renderMML() ); |
| 68 |
} |
| 69 |
} |