This commit is contained in:
wangjinlei
2024-07-17 09:23:45 +08:00
parent edf9deeb1a
commit 881ac3e056
1001 changed files with 41032 additions and 5452 deletions

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element;
use PHPUnit\Framework\TestCase;
class AbstractGroupElementTest extends TestCase
{
public function testConstruct(): void
{
$row = new Element\Row();
$this->assertIsArray($row->getElements());
$this->assertCount(0, $row->getElements());
}
public function testAdd(): void
{
$identifierA = new Element\Identifier('a');
$row = new Element\Row();
$this->assertCount(0, $row->getElements());
$this->assertInstanceOf(Element\AbstractGroupElement::class, $row->add($identifierA));
$this->assertCount(1, $row->getElements());
$this->assertEquals([$identifierA], $row->getElements());
}
public function testRemove(): void
{
$identifierA = new Element\Identifier('a');
$row = new Element\Row();
$row->add($identifierA);
$this->assertCount(1, $row->getElements());
$this->assertInstanceOf(Element\AbstractGroupElement::class, $row->remove($identifierA));
$this->assertCount(0, $row->getElements());
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element;
use PhpOffice\Math\Element\Fraction;
use PHPUnit\Framework\TestCase;
class FractionTest extends TestCase
{
public function testConstruct(): void
{
$identifierA = new Element\Identifier('a');
$identifierB = new Element\Identifier('b');
$fraction = new Fraction($identifierA, $identifierB);
$this->assertEquals($identifierA, $fraction->getNumerator());
$this->assertEquals($identifierB, $fraction->getDenominator());
}
public function testBase(): void
{
$identifierA = new Element\Identifier('a');
$identifierB = new Element\Identifier('b');
$identifierC = new Element\Identifier('c');
$fraction = new Fraction($identifierA, $identifierB);
$this->assertEquals($identifierA, $fraction->getNumerator());
$this->assertInstanceOf(Fraction::class, $fraction->setNumerator($identifierC));
$this->assertEquals($identifierC, $fraction->getNumerator());
}
public function testFraction(): void
{
$identifierA = new Element\Identifier('a');
$identifierB = new Element\Identifier('b');
$identifierC = new Element\Identifier('c');
$fraction = new Fraction($identifierA, $identifierB);
$this->assertEquals($identifierB, $fraction->getDenominator());
$this->assertInstanceOf(Fraction::class, $fraction->setDenominator($identifierC));
$this->assertEquals($identifierC, $fraction->getDenominator());
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element\Identifier;
use PHPUnit\Framework\TestCase;
class IdentifierTest extends TestCase
{
public function testConstruct(): void
{
$operator = new Identifier('x');
$this->assertEquals('x', $operator->getValue());
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element\Numeric;
use PHPUnit\Framework\TestCase;
class NumericTest extends TestCase
{
public function testConstruct(): void
{
$numeric = new Numeric(2);
$this->assertEquals(2, $numeric->getValue());
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element\Operator;
use PHPUnit\Framework\TestCase;
class OperatorTest extends TestCase
{
public function testConstruct(): void
{
$operator = new Operator('+');
$this->assertEquals('+', $operator->getValue());
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element\Semantics;
use PHPUnit\Framework\TestCase;
class SemanticsTest extends TestCase
{
public function testConstruct(): void
{
$semantics = new Semantics();
$this->assertIsArray($semantics->getAnnotations());
$this->assertCount(0, $semantics->getAnnotations());
}
public function testAnnotation(): void
{
$semantics = new Semantics();
$this->assertIsArray($semantics->getAnnotations());
$this->assertCount(0, $semantics->getAnnotations());
$this->assertInstanceOf(Semantics::class, $semantics->addAnnotation('encoding', 'content'));
$this->assertEquals(['encoding' => 'content'], $semantics->getAnnotations());
$this->assertCount(1, $semantics->getAnnotations());
$this->assertEquals('content', $semantics->getAnnotation('encoding'));
$this->assertNull($semantics->getAnnotation('notexisting'));
}
}

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Tests\PhpOffice\Math\Element;
use PhpOffice\Math\Element;
use PhpOffice\Math\Element\Superscript;
use PHPUnit\Framework\TestCase;
class SuperscriptTest extends TestCase
{
public function testConstruct(): void
{
$superscript = new Superscript(new Element\Identifier('a'), new Element\Identifier('a'));
$this->assertInstanceOf(Element\Identifier::class, $superscript->getBase());
$this->assertInstanceOf(Element\Identifier::class, $superscript->getSuperscript());
}
public function testBase(): void
{
$identifierA = new Element\Identifier('a');
$identifierB = new Element\Identifier('b');
$identifierC = new Element\Identifier('c');
$superscript = new Superscript($identifierA, $identifierB);
$this->assertEquals($identifierA, $superscript->getBase());
$this->assertInstanceOf(Superscript::class, $superscript->setBase($identifierC));
$this->assertEquals($identifierC, $superscript->getBase());
}
public function testSuperscript(): void
{
$identifierA = new Element\Identifier('a');
$identifierB = new Element\Identifier('b');
$identifierC = new Element\Identifier('c');
$superscript = new Superscript($identifierA, $identifierB);
$this->assertEquals($identifierB, $superscript->getSuperscript());
$this->assertInstanceOf(Superscript::class, $superscript->setSuperscript($identifierC));
$this->assertEquals($identifierC, $superscript->getSuperscript());
}
}