test documentation and started to enhance explicit coverage which dropped because of @covers

This commit is contained in:
Dennis Eichhorn 2019-12-07 10:16:54 +01:00
parent 5f632dfca0
commit 7eaf29e912
26 changed files with 900 additions and 44 deletions

View File

@ -156,7 +156,7 @@ final class Integer
public static function fermatFactor(int $value, int $limit = 1000000) : array public static function fermatFactor(int $value, int $limit = 1000000) : array
{ {
if (($value % 2) === 0) { if (($value % 2) === 0) {
throw new \Exception('Only odd integers are allowed'); throw new \InvalidArgumentException('Only odd integers are allowed');
} }
$a = (int) \ceil(\sqrt($value)); $a = (int) \ceil(\sqrt($value));

View File

@ -111,12 +111,12 @@ final class Numbers
{ {
$count = 0; $count = 0;
while ($n !== 0) { while ($n !== 0) {
if ($n & 1 == 1) { if ($n & 1 === 1) {
break; break;
} else {
++$count;
$n = $n >> 1;
} }
++$count;
$n = $n >> 1;
} }
return $count; return $count;

View File

@ -548,6 +548,27 @@ final class ModuleManager
// uninstall receiving from? no? // uninstall receiving from? no?
// uninstall module // uninstall module
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Uninstaller';
if (!Autoloader::exists($class)) {
throw new InvalidModuleException($info->getDirectory());
}
/** @var $class UninstallerAbstract */
$class::uninstall($this->app->dbPool, $info);
if (isset($this->installed[$module])) {
unset($this->installed[$module]);
}
if (isset($this->running[$module])) {
unset($this->running[$module]);
}
if (isset($this->active[$module])) {
unset($this->active[$module]);
}
return true; return true;
} catch (PathException $e) { } catch (PathException $e) {
return false; return false;

View File

@ -16,6 +16,7 @@ namespace phpOMS\Module;
use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder;
use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Uninstaller abstract class. * Uninstaller abstract class.
@ -40,7 +41,9 @@ abstract class UninstallerAbstract
*/ */
public static function uninstall(DatabasePool $dbPool, InfoManager $info) : void public static function uninstall(DatabasePool $dbPool, InfoManager $info) : void
{ {
// todo: remove routes
self::dropTables($dbPool, $info); self::dropTables($dbPool, $info);
self::unregisterFromDatabase($dbPool, $info);
} }
/** /**
@ -77,4 +80,31 @@ abstract class UninstallerAbstract
$builder->execute(); $builder->execute();
} }
/**
* Unregister module from database.
*
* @param DatabasePool $dbPool Database instance
* @param InfoManager $info Module info
*
* @return void
*
* @since 1.0.0
*/
public static function unregisterFromDatabase(DatabasePool $dbPool, InfoManager $info) : void
{
$queryLoad = new Builder($dbPool->get('delete'));
$queryLoad->prefix($dbPool->get('delete')->prefix);
$queryLoad->delete()
->from('module_load')
->where('module_load_from', '=', $info->getInternalName())
->execute();
$queryModule = new Builder($dbPool->get('delete'));
$queryModule->prefix($dbPool->get('delete')->prefix);
$queryModule->delete()
->from('module')
->where('module_id', '=', $info->getInternalName())
->execute();
}
} }

View File

@ -323,6 +323,7 @@ $GLOBALS['dbpool']->create('admin', $CONFIG['db']['core']['masters']['admin']);
$GLOBALS['dbpool']->create('select', $CONFIG['db']['core']['masters']['select']); $GLOBALS['dbpool']->create('select', $CONFIG['db']['core']['masters']['select']);
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']); $GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
$GLOBALS['dbpool']->create('update', $CONFIG['db']['core']['masters']['update']); $GLOBALS['dbpool']->create('update', $CONFIG['db']['core']['masters']['update']);
$GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete']);
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']); $GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get()); DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());

View File

@ -17,15 +17,27 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\Cuboid; use phpOMS\Math\Geometry\Shape\D3\Cuboid;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\CuboidTest: Cuboid shape
*
* @internal * @internal
*/ */
class CuboidTest extends \PHPUnit\Framework\TestCase class CuboidTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Cuboid
* @group framework
*/
public function testVolume() : void public function testVolume() : void
{ {
self::assertEqualsWithDelta(200, Cuboid::getVolume(10, 5, 4), 0.001); self::assertEqualsWithDelta(200, Cuboid::getVolume(10, 5, 4), 0.001);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Cuboid
* @group framework
*/
public function testSurface() : void public function testSurface() : void
{ {
self::assertEqualsWithDelta(220, Cuboid::getSurface(10, 5, 4), 0.001); self::assertEqualsWithDelta(220, Cuboid::getSurface(10, 5, 4), 0.001);

View File

@ -17,20 +17,37 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\Cylinder; use phpOMS\Math\Geometry\Shape\D3\Cylinder;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\CylinderTest: Cylinder shape
*
* @internal * @internal
*/ */
class CylinderTest extends \PHPUnit\Framework\TestCase class CylinderTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Cylinder
* @group framework
*/
public function testVolume() : void public function testVolume() : void
{ {
self::assertEqualsWithDelta(37.7, Cylinder::getVolume(2, 3), 0.01); self::assertEqualsWithDelta(37.7, Cylinder::getVolume(2, 3), 0.01);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Cylinder
* @group framework
*/
public function testSurface() : void public function testSurface() : void
{ {
self::assertEqualsWithDelta(62.83, Cylinder::getSurface(2, 3), 0.01); self::assertEqualsWithDelta(62.83, Cylinder::getSurface(2, 3), 0.01);
} }
/**
* @testdox The lateral surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Cylinder
* @group framework
*/
public function testLateralSurface() : void public function testLateralSurface() : void
{ {
self::assertEqualsWithDelta(37.7, Cylinder::getLateralSurface(2, 3), 0.01); self::assertEqualsWithDelta(37.7, Cylinder::getLateralSurface(2, 3), 0.01);

View File

@ -17,20 +17,37 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\Prism; use phpOMS\Math\Geometry\Shape\D3\Prism;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\PrismTest: Prism shape
*
* @internal * @internal
*/ */
class PrismTest extends \PHPUnit\Framework\TestCase class PrismTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated with the length
* @covers phpOMS\Math\Geometry\Shape\D3\Prism
* @group framework
*/
public function testVolumeByLength() : void public function testVolumeByLength() : void
{ {
self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularLength(3, 4, 12), 0.01); self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularLength(3, 4, 12), 0.01);
} }
/**
* @testdox The volume can be calculated with the radius
* @covers phpOMS\Math\Geometry\Shape\D3\Prism
* @group framework
*/
public function testVolumeByRadius() : void public function testVolumeByRadius() : void
{ {
self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularRadius(1.5, 4, 12), 0.01); self::assertEqualsWithDelta(3 * 3 * 12, Prism::getVolumeRegularRadius(1.5, 4, 12), 0.01);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Prism
* @group framework
*/
public function testSurface() public function testSurface()
{ {
self::assertEqualsWithDelta(3 * 3 * 2 + 3 * 12 * 4, Prism::getSurfaceRegularLength(3, 4, 12), 0.01); self::assertEqualsWithDelta(3 * 3 * 2 + 3 * 12 * 4, Prism::getSurfaceRegularLength(3, 4, 12), 0.01);

View File

@ -17,20 +17,37 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\RectangularPyramid; use phpOMS\Math\Geometry\Shape\D3\RectangularPyramid;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\RectangularPyramidTest: Rectangular pyramid shape
*
* @internal * @internal
*/ */
class RectangularPyramidTest extends \PHPUnit\Framework\TestCase class RectangularPyramidTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\RectangularPyramid
* @group framework
*/
public function testVolume() : void public function testVolume() : void
{ {
self::assertEqualsWithDelta(8, RectangularPyramid::getVolume(2, 3, 4), 0.01); self::assertEqualsWithDelta(8, RectangularPyramid::getVolume(2, 3, 4), 0.01);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\RectangularPyramid
* @group framework
*/
public function testSurface() : void public function testSurface() : void
{ {
self::assertEqualsWithDelta(26.91, RectangularPyramid::getSurface(2, 3, 4), 0.01); self::assertEqualsWithDelta(26.91, RectangularPyramid::getSurface(2, 3, 4), 0.01);
} }
/**
* @testdox The lateral surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\RectangularPyramid
* @group framework
*/
public function testLateralSurface() : void public function testLateralSurface() : void
{ {
self::assertEqualsWithDelta(20.91, RectangularPyramid::getLateralSurface(2, 3, 4), 0.01); self::assertEqualsWithDelta(20.91, RectangularPyramid::getLateralSurface(2, 3, 4), 0.01);

View File

@ -17,39 +17,71 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\Sphere; use phpOMS\Math\Geometry\Shape\D3\Sphere;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\SphereTest: Sphere shape
*
* @internal * @internal
*/ */
class SphereTest extends \PHPUnit\Framework\TestCase class SphereTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testVolume() : void public function testVolume() : void
{ {
$sphere = new Sphere(3); $sphere = new Sphere(3);
self::assertEqualsWithDelta(113.1, $sphere->getVolume(), 0.1); self::assertEqualsWithDelta(113.1, $sphere->getVolume(), 0.1);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testSurface() : void public function testSurface() : void
{ {
$sphere = new Sphere(3); $sphere = new Sphere(3);
self::assertEqualsWithDelta(113.1, $sphere->getSurface(), 0.1); self::assertEqualsWithDelta(113.1, $sphere->getSurface(), 0.1);
} }
/**
* @testdox The distance on a sphere can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testDistanceOnSphere() : void public function testDistanceOnSphere() : void
{ {
self::assertEqualsWithDelta(422740, Sphere::distance2PointsOnSphere(32.9697, -96.80322, 29.46786, -98.53506), 50); self::assertEqualsWithDelta(422740, Sphere::distance2PointsOnSphere(32.9697, -96.80322, 29.46786, -98.53506), 50);
} }
/**
* @testdox The sphere can be created by its radius
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testGetSphereByRadius() : void public function testGetSphereByRadius() : void
{ {
$sphere = Sphere::byRadius(3); $sphere = Sphere::byRadius(3);
self::assertEqualsWithDelta(3, $sphere->getRadius(), 0.1); self::assertEqualsWithDelta(3, $sphere->getRadius(), 0.1);
} }
/**
* @testdox The sphere can be created by its volume
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testGetSphereByVolume() : void public function testGetSphereByVolume() : void
{ {
$sphere = Sphere::byVolume(4); $sphere = Sphere::byVolume(4);
self::assertEqualsWithDelta(4, $sphere->getVolume(), 0.1); self::assertEqualsWithDelta(4, $sphere->getVolume(), 0.1);
} }
/**
* @testdox The sphere can be created by its surface
* @covers phpOMS\Math\Geometry\Shape\D3\Sphere
* @group framework
*/
public function testGetSphereBySurface() : void public function testGetSphereBySurface() : void
{ {
$sphere = Sphere::bySurface(5); $sphere = Sphere::bySurface(5);

View File

@ -17,20 +17,37 @@ namespace phpOMS\tests\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D3\Tetrahedron; use phpOMS\Math\Geometry\Shape\D3\Tetrahedron;
/** /**
* @testdox phpOMS\tests\Math\Geometry\Shape\D3\TetrahedronTest: Tetrahedron shape
*
* @internal * @internal
*/ */
class TetrahedronTest extends \PHPUnit\Framework\TestCase class TetrahedronTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The volume can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Tetrahedron
* @group framework
*/
public function testVolume() : void public function testVolume() : void
{ {
self::assertEqualsWithDelta(3.18, Tetrahedron::getVolume(3), 0.01); self::assertEqualsWithDelta(3.18, Tetrahedron::getVolume(3), 0.01);
} }
/**
* @testdox The surface can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Tetrahedron
* @group framework
*/
public function testSurface() : void public function testSurface() : void
{ {
self::assertEqualsWithDelta(15.59, Tetrahedron::getSurface(3), 0.01); self::assertEqualsWithDelta(15.59, Tetrahedron::getSurface(3), 0.01);
} }
/**
* @testdox The face area can be calculated
* @covers phpOMS\Math\Geometry\Shape\D3\Tetrahedron
* @group framework
*/
public function testFaceArea() : void public function testFaceArea() : void
{ {
self::assertEqualsWithDelta(3.9, Tetrahedron::getFaceArea(3), 0.01); self::assertEqualsWithDelta(3.9, Tetrahedron::getFaceArea(3), 0.01);

View File

@ -19,11 +19,18 @@ use phpOMS\Math\Matrix\Matrix;
use phpOMS\Math\Matrix\Vector; use phpOMS\Math\Matrix\Vector;
/** /**
* @testdox phpOMS\tests\Math\Matrix\CholeskyDecompositionTest: Cholesky decomposition
*
* @internal * @internal
*/ */
class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
{ {
public function testComposition() : void /**
* @testdox The decomposition can be created and the original matrix can be computed
* @covers phpOMS\Math\Matrix\CholeskyDecomposition
* @group framework
*/
public function testDecomposition() : void
{ {
$A = new Matrix(); $A = new Matrix();
$A->setMatrix([ $A->setMatrix([
@ -43,7 +50,12 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
); );
} }
public function testDecomposition() : void /**
* @testdox The decomposition matrix has the expected values
* @covers phpOMS\Math\Matrix\CholeskyDecomposition
* @group framework
*/
public function testL() : void
{ {
$A = new Matrix(); $A = new Matrix();
$A->setMatrix([ $A->setMatrix([
@ -59,10 +71,43 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
[3, 3, 0], [3, 3, 0],
[-1, 1, 3], [-1, 1, 3],
], $cholesky->getL()->toArray(), 0.2); ], $cholesky->getL()->toArray(), 0.2);
self::assertTrue($cholesky->isSpd());
} }
/**
* @testdox A matrix can be checked for symmetric positivity
* @covers phpOMS\Math\Matrix\CholeskyDecomposition
* @group framework
*/
public function testSymmetricPositive() : void
{
$A = new Matrix();
$A->setMatrix([
[25, 15, -5],
[15, 17, 0],
[-5, 0, 11],
]);
$cholesky = new CholeskyDecomposition($A);
self::assertTrue($cholesky->isSpd());
$B = new Matrix();
$B->setMatrix([
[25, 15, 5],
[15, 17, 0],
[-5, 0, 11],
]);
$choleskyB = new CholeskyDecomposition($B);
self::assertTrue($choleskyB->isSpd());
}
/**
* @testdox The equation Ax = b can be solved
* @covers phpOMS\Math\Matrix\CholeskyDecomposition
* @group framework
*/
public function testSolve() : void public function testSolve() : void
{ {
$A = new Matrix(); $A = new Matrix();
@ -79,6 +124,11 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
self::assertEqualsWithDelta([[1], [2], [3]], $cholesky->solve($vec)->toArray(), 0.2); self::assertEqualsWithDelta([[1], [2], [3]], $cholesky->solve($vec)->toArray(), 0.2);
} }
/**
* @testdox A invalid vector throws a InvalidDimensionException
* @covers phpOMS\Math\Matrix\CholeskyDecomposition
* @group framework
*/
public function testInvalidDimension() : void public function testInvalidDimension() : void
{ {
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);

View File

@ -18,11 +18,18 @@ use phpOMS\Math\Matrix\EigenvalueDecomposition;
use phpOMS\Math\Matrix\Matrix; use phpOMS\Math\Matrix\Matrix;
/** /**
* @testdox phpOMS\tests\Math\Matrix\EigenvalueDecompositionTest: Eigenvalue decomposition
*
* @internal * @internal
*/ */
class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
{ {
public function testSymmetricMatrix() : void /**
* @testdox A matrix can be checked for symmetry
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testSymmetricSymmetryMatrix() : void
{ {
$A = new Matrix(); $A = new Matrix();
$A->setMatrix([ $A->setMatrix([
@ -34,13 +41,76 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
$eig = new EigenvalueDecomposition($A); $eig = new EigenvalueDecomposition($A);
self::assertTrue($eig->isSymmetric()); self::assertTrue($eig->isSymmetric());
$B = new Matrix();
$B->setMatrix([
[3, 1, 2],
[1, 2, 2],
[1, 2, 2],
]);
$eigB = new EigenvalueDecomposition($B);
self::assertFalse($eigB->isSymmetric());
}
/**
* @testdox The eigenvalues can be calculated for a symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testSymmetricMatrixEigenvalues() : void
{
$A = new Matrix();
$A->setMatrix([
[3, 1, 1],
[1, 2, 2],
[1, 2, 2],
]);
$eig = new EigenvalueDecomposition($A);
self::assertEqualsWithDelta([0, 2, 5], $eig->getRealEigenvalues()->toArray(), 0.2); self::assertEqualsWithDelta([0, 2, 5], $eig->getRealEigenvalues()->toArray(), 0.2);
}
/**
* @testdox The V matrix of the decomposition can be calculated for a symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testSymmetricMatrixV() : void
{
$A = new Matrix();
$A->setMatrix([
[3, 1, 1],
[1, 2, 2],
[1, 2, 2],
]);
$eig = new EigenvalueDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[0, 2/\sqrt(6), 1/\sqrt(3)], [0, 2/\sqrt(6), 1/\sqrt(3)],
[1/\sqrt(2), -1/\sqrt(6), 1/\sqrt(3)], [1/\sqrt(2), -1/\sqrt(6), 1/\sqrt(3)],
[-1/\sqrt(2), -1/\sqrt(6), 1/\sqrt(3)], [-1/\sqrt(2), -1/\sqrt(6), 1/\sqrt(3)],
], $eig->getV()->toArray(), 0.2); ], $eig->getV()->toArray(), 0.2);
}
/**
* @testdox The D matrix of the decomposition can be calculated for a symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testSymmetricMatrixD() : void
{
$A = new Matrix();
$A->setMatrix([
[3, 1, 1],
[1, 2, 2],
[1, 2, 2],
]);
$eig = new EigenvalueDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[0, 0, 0], [0, 0, 0],
@ -49,7 +119,12 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
], $eig->getD()->toArray(), 0.2); ], $eig->getD()->toArray(), 0.2);
} }
public function testNonSymmetricMatrix() : void /**
* @testdox The eigenvalues can be calculated for a none-symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testNonSymmetricMatrixEigenvalues() : void
{ {
$A = new Matrix(); $A = new Matrix();
$A->setMatrix([ $A->setMatrix([
@ -60,14 +135,47 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
$eig = new EigenvalueDecomposition($A); $eig = new EigenvalueDecomposition($A);
self::assertFalse($eig->isSymmetric());
self::assertEqualsWithDelta([-5, 3, 6], $eig->getRealEigenvalues()->toArray(), 0.2); self::assertEqualsWithDelta([-5, 3, 6], $eig->getRealEigenvalues()->toArray(), 0.2);
}
/**
* @testdox The V matrix of the decomposition can be calculated for a none-symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testNonSymmetricMatrixV() : void
{
$A = new Matrix();
$A->setMatrix([
[-2, -4, 2],
[-2, 1, 2],
[4, 2, 5],
]);
$eig = new EigenvalueDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[-\sqrt(2/3), \sqrt(2/7), -1/\sqrt(293)], [-\sqrt(2/3), \sqrt(2/7), -1/\sqrt(293)],
[-1/\sqrt(6), -3/\sqrt(14), -6/\sqrt(293)], [-1/\sqrt(6), -3/\sqrt(14), -6/\sqrt(293)],
[1/\sqrt(6), -1/\sqrt(14), -16/\sqrt(293)], [1/\sqrt(6), -1/\sqrt(14), -16/\sqrt(293)],
], $eig->getV()->toArray(), 0.2); ], $eig->getV()->toArray(), 0.2);
}
/**
* @testdox The D matrix of the decomposition can be calculated for a none-symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testNonSymmetricMatrixD() : void
{
$A = new Matrix();
$A->setMatrix([
[-2, -4, 2],
[-2, 1, 2],
[4, 2, 5],
]);
$eig = new EigenvalueDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[-5, 0, 0], [-5, 0, 0],
@ -76,6 +184,11 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
], $eig->getD()->toArray(), 0.2); ], $eig->getD()->toArray(), 0.2);
} }
/**
* @testdox The decomposition can be created and the original matrix can be computed for a symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testCompositeSymmetric() : void public function testCompositeSymmetric() : void
{ {
$A = new Matrix(); $A = new Matrix();
@ -96,6 +209,11 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
, 0.2); , 0.2);
} }
/**
* @testdox The decomposition can be created and the original matrix can be computed for a none-symmetric matrix
* @covers phpOMS\Math\Matrix\EigenvalueDecomposition
* @group framework
*/
public function testCompositeNonSymmetric() : void public function testCompositeNonSymmetric() : void
{ {
$A = new Matrix(); $A = new Matrix();

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Matrix;
use phpOMS\Math\Matrix\IdentityMatrix; use phpOMS\Math\Matrix\IdentityMatrix;
/** /**
* @testdox phpOMS\tests\Math\Matrix\IdentityMatrixTest: Identity matrix
*
* @internal * @internal
*/ */
class IdentityMatrixTest extends \PHPUnit\Framework\TestCase class IdentityMatrixTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The identity matrix is the identity
* @covers phpOMS\Math\Matrix\IdentityMatrix
* @group framework
*/
public function testIdentity() : void public function testIdentity() : void
{ {
$id = new IdentityMatrix(5); $id = new IdentityMatrix(5);

View File

@ -19,11 +19,18 @@ use phpOMS\Math\Matrix\Matrix;
use phpOMS\Math\Matrix\Vector; use phpOMS\Math\Matrix\Vector;
/** /**
* @testdox phpOMS\tests\Math\Matrix\LUDecompositionTest: LU decomposition
*
* @internal * @internal
*/ */
class LUDecompositionTest extends \PHPUnit\Framework\TestCase class LUDecompositionTest extends \PHPUnit\Framework\TestCase
{ {
public function testDecomposition() : void /**
* @testdox The L matrix of the decomposition can be calculated
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testL() : void
{ {
$B = new Matrix(); $B = new Matrix();
$B->setMatrix([ $B->setMatrix([
@ -39,22 +46,49 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase
[0.6, 1, 0], [0.6, 1, 0],
[-0.2, 0.375, 1], [-0.2, 0.375, 1],
], $lu->getL()->toArray(), 0.2); ], $lu->getL()->toArray(), 0.2);
}
/**
* @testdox The U matrix of the decomposition can be calculated
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testU() : void
{
$B = new Matrix();
$B->setMatrix([
[25, 15, -5],
[15, 17, 0],
[-5, 0, 11],
]);
$lu = new LUDecomposition($B);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[25, 15, -5], [25, 15, -5],
[0, 8, 3], [0, 8, 3],
[0, 0, 8.875], [0, 0, 8.875],
], $lu->getU()->toArray(), 0.2); ], $lu->getU()->toArray(), 0.2);
$vec = new Vector();
$vec->setMatrix([[40], [49], [28]]);
self::assertTrue($lu->isNonSingular());
self::assertEqualsWithDelta([[1], [2], [3]], $lu->solve($vec)->toArray(), 0.2);
self::assertEquals([0, 1, 2], $lu->getPivot());
} }
public function testSingularMatrix() : void /**
* @testdox The matrix can be checked for singularity
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testSingularity() : void
{ {
$A = new Matrix();
$A->setMatrix([
[25, 15, -5],
[15, 17, 0],
[-5, 0, 11],
]);
$lu = new LUDecomposition($A);
self::assertTrue($lu->isNonSingular());
$B = new Matrix(); $B = new Matrix();
$B->setMatrix([ $B->setMatrix([
[25, 15, -5], [25, 15, -5],
@ -62,11 +96,56 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase
[0, 0, 2], [0, 0, 2],
]); ]);
$lu = new LUDecomposition($B); $luB = new LUDecomposition($B);
self::assertFalse($lu->isNonSingular()); self::assertFalse($luB->isNonSingular());
} }
/**
* @testdox The equation Ax = b can be solved for a none-singular matrix
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testSolve() : void
{
$B = new Matrix();
$B->setMatrix([
[25, 15, -5],
[15, 17, 0],
[-5, 0, 11],
]);
$lu = new LUDecomposition($B);
$vec = new Vector();
$vec->setMatrix([[40], [49], [28]]);
self::assertEqualsWithDelta([[1], [2], [3]], $lu->solve($vec)->toArray(), 0.2);
}
/**
* @testdox The pivots of the decomposition can be calculated
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testPivot() : void
{
$B = new Matrix();
$B->setMatrix([
[25, 15, -5],
[15, 17, 0],
[-5, 0, 11],
]);
$lu = new LUDecomposition($B);
self::assertEquals([0, 1, 2], $lu->getPivot());
}
/**
* @testdox The equation Ax = b can be solved for a singular matrix
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testSolveOfSingularMatrix() : void public function testSolveOfSingularMatrix() : void
{ {
self::expectException(\Exception::class); self::expectException(\Exception::class);
@ -86,6 +165,11 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase
$lu->solve($vec); $lu->solve($vec);
} }
/**
* @testdox The decomposition can be created and the original matrix can be computed
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testComposition() : void public function testComposition() : void
{ {
$A = new Matrix(); $A = new Matrix();
@ -106,6 +190,11 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox A invalid vector throws a InvalidDimensionException
* @covers phpOMS\Math\Matrix\LUDecomposition
* @group framework
*/
public function testInvalidDimension() : void public function testInvalidDimension() : void
{ {
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);

View File

@ -18,7 +18,7 @@ use phpOMS\Math\Matrix\Matrix;
use phpOMS\Math\Matrix\Vector; use phpOMS\Math\Matrix\Vector;
/** /**
* @testdox phpOMS\tests\Math\MatrixTest: Matrix operations * @testdox phpOMS\tests\Math\Matrix\MatrixTest: Matrix operations
* *
* @internal * @internal
*/ */

View File

@ -19,11 +19,18 @@ use phpOMS\Math\Matrix\QRDecomposition;
use phpOMS\Math\Matrix\Vector; use phpOMS\Math\Matrix\Vector;
/** /**
* @testdox phpOMS\tests\Math\Matrix\QRDecompositionTest: QR decomposition
*
* @internal * @internal
*/ */
class QRDecompositionTest extends \PHPUnit\Framework\TestCase class QRDecompositionTest extends \PHPUnit\Framework\TestCase
{ {
public function testDecomposition() : void /**
* @testdox A matrix can be checked if it has a full rank
* @covers phpOMS\Math\Matrix\QRDecomposition
* @group framework
*/
public function testRank() : void
{ {
$A = new Matrix(); $A = new Matrix();
$A->setMatrix([ $A->setMatrix([
@ -35,12 +42,46 @@ class QRDecompositionTest extends \PHPUnit\Framework\TestCase
$QR = new QRDecomposition($A); $QR = new QRDecomposition($A);
self::assertTrue($QR->isFullRank()); self::assertTrue($QR->isFullRank());
}
/**
* @testdox The Q matrix of the decomposition can be calculated
* @covers phpOMS\Math\Matrix\QRDecomposition
* @group framework
*/
public function testQ() : void
{
$A = new Matrix();
$A->setMatrix([
[12, -51, 4],
[6, 167, -68],
[-4, 24, -41],
]);
$QR = new QRDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[-6 / 7, 69 / 175, -58 / 175], [-6 / 7, 69 / 175, -58 / 175],
[-3 / 7, -158 / 175, -6 / 175], [-3 / 7, -158 / 175, -6 / 175],
[2 / 7, -6 / 35, -33 / 35], [2 / 7, -6 / 35, -33 / 35],
], $QR->getQ()->toArray(), 0.2); ], $QR->getQ()->toArray(), 0.2);
}
/**
* @testdox The R matrix of the decomposition can be calculated
* @covers phpOMS\Math\Matrix\QRDecomposition
* @group framework
*/
public function testR() : void
{
$A = new Matrix();
$A->setMatrix([
[12, -51, 4],
[6, 167, -68],
[-4, 24, -41],
]);
$QR = new QRDecomposition($A);
self::assertEqualsWithDelta([ self::assertEqualsWithDelta([
[-14, -21, 14], [-14, -21, 14],
@ -49,6 +90,11 @@ class QRDecompositionTest extends \PHPUnit\Framework\TestCase
], $QR->getR()->toArray(), 0.2); ], $QR->getR()->toArray(), 0.2);
} }
/**
* @testdox The decomposition can be created and the original matrix can be computed
* @covers phpOMS\Math\Matrix\QRDecomposition
* @group framework
*/
public function testComposition() : void public function testComposition() : void
{ {
$A = new Matrix(); $A = new Matrix();
@ -69,6 +115,11 @@ class QRDecompositionTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The equation Ax = b can be solved
* @covers phpOMS\Math\Matrix\QRDecomposition
* @group framework
*/
public function testSolve() : void public function testSolve() : void
{ {
$A = new Matrix(); $A = new Matrix();

View File

@ -17,7 +17,7 @@ namespace phpOMS\tests\Math\Matrix;
use phpOMS\Math\Matrix\Vector; use phpOMS\Math\Matrix\Vector;
/** /**
* @testdox phpOMS\tests\Math\VectorTest: Vector operations * @testdox phpOMS\tests\Math\Matrix\VectorTest: Vector operations
* *
* @internal * @internal
*/ */

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Number\Complex; use phpOMS\Math\Number\Complex;
/** /**
* @testdox phpOMS\tests\Math\Number\ComplexTest: Complex number operations
*
* @internal * @internal
*/ */
class ComplexTest extends \PHPUnit\Framework\TestCase class ComplexTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The complex number has the expected default values after initialization
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testDefault() : void public function testDefault() : void
{ {
$cpl = new Complex(); $cpl = new Complex();
@ -29,49 +36,119 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $cpl->render()); self::assertEquals('', $cpl->render());
} }
public function testSetGet() : void /**
* @testdox The real and imaginary part can be set during initialization and returned
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testConstructorInputOutput() : void
{ {
$cpl = new Complex(1, 2); $cpl = new Complex(1, 2);
self::assertEquals(1, $cpl->re()); self::assertEquals(1, $cpl->re());
self::assertEquals(2, $cpl->im()); self::assertEquals(2, $cpl->im());
} }
public function testAdd() : void /**
* @testdox A complex number can be added to a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testAddComplex() : void
{ {
$cpl1 = new Complex(2, 3); $cpl1 = new Complex(2, 3);
$cpl2 = new Complex(3, 4); $cpl2 = new Complex(3, 4);
self::assertEquals('5.00 + 7.00i', $cpl1->add($cpl2)->render()); self::assertEquals('5.00 + 7.00i', $cpl1->add($cpl2)->render());
}
/**
* @testdox A real number can be added to a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testAddReal() : void
{
$cpl1 = new Complex(2, 3);
self::assertEquals('6.00 + 3.00i', $cpl1->add(4)->render()); self::assertEquals('6.00 + 3.00i', $cpl1->add(4)->render());
} }
public function testSub() : void /**
* @testdox A complex number can be subtracted from a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testSubComplex() : void
{ {
$cpl1 = new Complex(2, 3); $cpl1 = new Complex(2, 3);
$cpl2 = new Complex(3, 4); $cpl2 = new Complex(3, 4);
self::assertEquals('-1.00 - 1.00i', $cpl1->sub($cpl2)->render()); self::assertEquals('-1.00 - 1.00i', $cpl1->sub($cpl2)->render());
}
/**
* @testdox A real number can be subtracted from a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testSubReal() : void
{
$cpl1 = new Complex(2, 3);
self::assertEquals('-2.00 + 3.00i', $cpl1->sub(4)->render()); self::assertEquals('-2.00 + 3.00i', $cpl1->sub(4)->render());
} }
public function testMult() : void /**
* @testdox A complex number can be multiplicated with a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testMultComplex() : void
{ {
$cpl1 = new Complex(2, 3); $cpl1 = new Complex(2, 3);
$cpl2 = new Complex(3, 4); $cpl2 = new Complex(3, 4);
self::assertEquals('-6.00 + 17.00i', $cpl1->mult($cpl2)->render()); self::assertEquals('-6.00 + 17.00i', $cpl1->mult($cpl2)->render());
}
/**
* @testdox A real number can be multiplicated with a complex number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testMultReal() : void
{
$cpl1 = new Complex(2, 3);
self::assertEquals('8.00 + 12.00i', $cpl1->mult(4)->render()); self::assertEquals('8.00 + 12.00i', $cpl1->mult(4)->render());
} }
public function testDiv() : void /**
* @testdox A complex number can be devided by a complex number number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testDivComplex() : void
{ {
$cpl1 = new Complex(2, 3); $cpl1 = new Complex(2, 3);
$cpl2 = new Complex(3, 4); $cpl2 = new Complex(3, 4);
self::assertEquals('0.72 + 0.04i', $cpl1->div($cpl2)->render(2)); self::assertEquals('0.72 + 0.04i', $cpl1->div($cpl2)->render(2));
}
/**
* @testdox A complex number can be devided by a real number
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testDivReal() : void
{
$cpl1 = new Complex(2, 3);
self::assertEquals('0.50 + 0.75i', $cpl1->div(4)->render(2)); self::assertEquals('0.50 + 0.75i', $cpl1->div(4)->render(2));
} }
/**
* @testdox A complex number can be conjugated
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testConjugate() : void public function testConjugate() : void
{ {
$cpl = new Complex(4, 3); $cpl = new Complex(4, 3);
@ -79,6 +156,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
self::assertEquals('4 - 3i', $cpl->conjugate()->render(0)); self::assertEquals('4 - 3i', $cpl->conjugate()->render(0));
} }
/**
* @testdox The reciprocal of a complex number can be calculated
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testReciprocal() : void public function testReciprocal() : void
{ {
$cpl = new Complex(4, 3); $cpl = new Complex(4, 3);
@ -86,16 +168,37 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
self::assertEquals('0.16 - 0.12i', $cpl->reciprocal()->render(2)); self::assertEquals('0.16 - 0.12i', $cpl->reciprocal()->render(2));
} }
public function testPower() : void /**
* @testdox A complex number can be squared
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testSquare() : void
{ {
$cpl = new Complex(4, 3); $cpl = new Complex(4, 3);
self::assertEquals('7.00 + 24.00i', $cpl->square()->render()); self::assertEquals('7.00 + 24.00i', $cpl->square()->render());
}
/**
* @testdox The real power of a complex number can be caluclated
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testPower() : void
{
$cpl = new Complex(4, 3);
self::assertEquals('7.00 + 24.00i', $cpl->pow(2)->render()); self::assertEquals('7.00 + 24.00i', $cpl->pow(2)->render());
self::assertEquals('-44.00 + 117.00i', $cpl->pow(3)->render()); self::assertEquals('-44.00 + 117.00i', $cpl->pow(3)->render());
self::assertEquals('1.00', $cpl->pow(0)->render()); self::assertEquals('1.00', $cpl->pow(0)->render());
} }
/**
* @testdox The absolute value of a complex number can be calculated
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testAbs() : void public function testAbs() : void
{ {
$cpl = new Complex(4, 3); $cpl = new Complex(4, 3);
@ -103,6 +206,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
self::assertEqualsWithDelta(5, $cpl->abs(), 0.01); self::assertEqualsWithDelta(5, $cpl->abs(), 0.01);
} }
/**
* @testdox The square root of a complex number can be calculated
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testSqrt() : void public function testSqrt() : void
{ {
$cpl = new Complex(4, 3); $cpl = new Complex(4, 3);
@ -112,6 +220,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
self::assertEquals('1.04 + 1.44i', $cpl2->sqrt()->render()); self::assertEquals('1.04 + 1.44i', $cpl2->sqrt()->render());
} }
/**
* @testdox A invalid type addition throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testInvalidAdd() : void public function testInvalidAdd() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -120,6 +233,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
$cpl->add(true); $cpl->add(true);
} }
/**
* @testdox A invalid type subtraction throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testInvalidSub() : void public function testInvalidSub() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -128,6 +246,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
$cpl->sub(true); $cpl->sub(true);
} }
/**
* @testdox A invalid type cannot multiplication throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testInvalidMult() : void public function testInvalidMult() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -136,6 +259,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
$cpl->mult(true); $cpl->mult(true);
} }
/**
* @testdox A invalid type division throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testInvalidDiv() : void public function testInvalidDiv() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);
@ -144,6 +272,11 @@ class ComplexTest extends \PHPUnit\Framework\TestCase
$cpl->div(true); $cpl->div(true);
} }
/**
* @testdox The power of a invalid type throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Complex
* @group framework
*/
public function testInvalidPow() : void public function testInvalidPow() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Number\Integer; use phpOMS\Math\Number\Integer;
/** /**
* @testdox phpOMS\tests\Math\Number\IntegerTest: Integer operations
*
* @internal * @internal
*/ */
class IntegerTest extends \PHPUnit\Framework\TestCase class IntegerTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A value can be checked to be an intager
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testIsInteger() : void public function testIsInteger() : void
{ {
self::assertTrue(Integer::isInteger(4)); self::assertTrue(Integer::isInteger(4));
@ -28,6 +35,11 @@ class IntegerTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Integer::isInteger('3')); self::assertFalse(Integer::isInteger('3'));
} }
/**
* @testdox An integer can be factorized
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testFactorization() : void public function testFactorization() : void
{ {
$arr = [2, 2, 5, 5]; $arr = [2, 2, 5, 5];
@ -55,20 +67,43 @@ class IntegerTest extends \PHPUnit\Framework\TestCase
self::assertEquals([], Integer::trialFactorization(1)); self::assertEquals([], Integer::trialFactorization(1));
} }
public function testOther() : void /**
* @testdox The Pollard's Roh algorithm calculates a factor of an integer
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testPollardsRho() : void
{ {
self::assertEquals(101, Integer::pollardsRho(10403, 2, 1, 2, 2)); self::assertEquals(101, Integer::pollardsRho(10403, 2, 1, 2, 2));
}
/**
* @testdox The Fermat factorization calculates a factor of an integer
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testFermatFactor() : void
{
self::assertEquals([59, 101], Integer::fermatFactor(5959)); self::assertEquals([59, 101], Integer::fermatFactor(5959));
} }
/**
* @testdox A even number for the fermat factorization throws a InvalidArgumentException
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testInvalidFermatParameter() : void public function testInvalidFermatParameter() : void
{ {
self::expectException(\Exception::class); self::expectException(\InvalidArgumentException::class);
Integer::fermatFactor(8); Integer::fermatFactor(8);
} }
/**
* @testdox The greatest common divisor can be calculated
* @covers phpOMS\Math\Number\Integer
* @group framework
*/
public function testGCD() : void public function testGCD() : void
{ {
self::assertEquals(4, Integer::greatestCommonDivisor(4, 4)); self::assertEquals(4, Integer::greatestCommonDivisor(4, 4));

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Number\Natural; use phpOMS\Math\Number\Natural;
/** /**
* @testdox phpOMS\tests\Math\Number\NaturalTest: Natural number operations
*
* @internal * @internal
*/ */
class NaturalTest extends \PHPUnit\Framework\TestCase class NaturalTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A number can be checked to be natural
* @covers phpOMS\Math\Number\Natural
* @group framework
*/
public function testIsNatural() : void public function testIsNatural() : void
{ {
self::assertTrue(Natural::isNatural(1235)); self::assertTrue(Natural::isNatural(1235));

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Number\Numbers; use phpOMS\Math\Number\Numbers;
/** /**
* @testdox phpOMS\tests\Math\Number\NumbersTest: General number utilities
*
* @internal * @internal
*/ */
class NumbersTest extends \PHPUnit\Framework\TestCase class NumbersTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A number can be checked to be perfect
* @covers phpOMS\Math\Number\Numbers
* @group framework
*/
public function testPerfect() : void public function testPerfect() : void
{ {
self::assertTrue(Numbers::isPerfect(496)); self::assertTrue(Numbers::isPerfect(496));
@ -29,6 +36,11 @@ class NumbersTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Numbers::isPerfect(100)); self::assertFalse(Numbers::isPerfect(100));
} }
/**
* @testdox A number can be checked to be self-describing
* @covers phpOMS\Math\Number\Numbers
* @group framework
*/
public function testSelfdescribing() : void public function testSelfdescribing() : void
{ {
self::assertFalse(Numbers::isSelfdescribing(2029)); self::assertFalse(Numbers::isSelfdescribing(2029));
@ -36,6 +48,11 @@ class NumbersTest extends \PHPUnit\Framework\TestCase
self::assertTrue(Numbers::isSelfdescribing(3211000)); self::assertTrue(Numbers::isSelfdescribing(3211000));
} }
/**
* @testdox A number can be checked to be squared
* @covers phpOMS\Math\Number\Numbers
* @group framework
*/
public function testSquare() : void public function testSquare() : void
{ {
self::assertTrue(Numbers::isSquare(81)); self::assertTrue(Numbers::isSquare(81));
@ -43,6 +60,11 @@ class NumbersTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Numbers::isSquare(5545348)); self::assertFalse(Numbers::isSquare(5545348));
} }
/**
* @testdox The amount of trailing zeros can be counted
* @covers phpOMS\Math\Number\Numbers
* @group framework
*/
public function testZeroCounting() : void public function testZeroCounting() : void
{ {
self::assertEquals(3, Numbers::countTrailingZeros(1000)); self::assertEquals(3, Numbers::countTrailingZeros(1000));

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Number\Prime; use phpOMS\Math\Number\Prime;
/** /**
* @testdox phpOMS\tests\Math\Number\PrimeTest: Prime number utilities
*
* @internal * @internal
*/ */
class PrimeTest extends \PHPUnit\Framework\TestCase class PrimeTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox A number can be checked to be a prime number
* @covers phpOMS\Math\Number\Prime
* @group framework
*/
public function testPrime() : void public function testPrime() : void
{ {
self::assertTrue(Prime::isPrime(2)); self::assertTrue(Prime::isPrime(2));
@ -28,12 +35,22 @@ class PrimeTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Prime::isPrime(998)); self::assertFalse(Prime::isPrime(998));
} }
/**
* @testdox A prime number can be generat3ed with the sieve of erathosthenes
* @covers phpOMS\Math\Number\Prime
* @group framework
*/
public function testSieve() : void public function testSieve() : void
{ {
self::assertTrue(Prime::isPrime(Prime::sieveOfEratosthenes(12)[3])); self::assertTrue(Prime::isPrime(Prime::sieveOfEratosthenes(12)[3]));
self::assertTrue(Prime::isPrime(Prime::sieveOfEratosthenes(51)[7])); self::assertTrue(Prime::isPrime(Prime::sieveOfEratosthenes(51)[7]));
} }
/**
* @testdox A number can be checked to be prime with the rabin test
* @covers phpOMS\Math\Number\Prime
* @group framework
*/
public function testRabin() : void public function testRabin() : void
{ {
self::assertTrue(Prime::rabinTest(2)); self::assertTrue(Prime::rabinTest(2));
@ -43,18 +60,26 @@ class PrimeTest extends \PHPUnit\Framework\TestCase
self::assertFalse(Prime::rabinTest(998)); self::assertFalse(Prime::rabinTest(998));
} }
/**
* @testdox Mersenne numbers can be calculated
* @covers phpOMS\Math\Number\Prime
* @group framework
*/
public function testMersenne() : void public function testMersenne() : void
{ {
self::assertEquals(2047, Prime::mersenne(11)); self::assertEquals(2047, Prime::mersenne(11));
self::assertTrue(Prime::isMersenne(Prime::mersenne(2))); self::assertTrue(Prime::isMersenne(Prime::mersenne(2)));
self::assertTrue(Prime::isMersenne(Prime::mersenne(4))); self::assertTrue(Prime::isMersenne(Prime::mersenne(4)));
self::assertFalse(Prime::isMersenne(2046));
} }
/**
* @testdox A number can be checked to be a mersenne number
* @covers phpOMS\Math\Number\Prime
* @group framework
*/
public function testIsMersenne() : void public function testIsMersenne() : void
{ {
self::assertTrue(Prime::isMersenne(Prime::mersenne(2))); self::assertTrue(Prime::isMersenne(8191));
self::assertTrue(Prime::isMersenne(Prime::mersenne(4)));
self::assertFalse(Prime::isMersenne(2046)); self::assertFalse(Prime::isMersenne(2046));
} }
} }

View File

@ -17,10 +17,17 @@ namespace phpOMS\tests\Math\Number;
use phpOMS\Math\Topology\Metrics2D; use phpOMS\Math\Topology\Metrics2D;
/** /**
* @testdox phpOMS\tests\Math\Topology\Metrics2DTest: Metric/distance calculations
*
* @internal * @internal
*/ */
class Metrics2DTest extends \PHPUnit\Framework\TestCase class Metrics2DTest extends \PHPUnit\Framework\TestCase
{ {
/**
* @testdox The manhattan distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testManhattan() : void public function testManhattan() : void
{ {
self::assertEquals( self::assertEquals(
@ -29,6 +36,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The euclidean distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testEuclidean() : void public function testEuclidean() : void
{ {
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
@ -38,6 +50,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The chebyshev distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testChebyshev() : void public function testChebyshev() : void
{ {
self::assertEquals( self::assertEquals(
@ -46,6 +63,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The minkowski distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testMinkowski() : void public function testMinkowski() : void
{ {
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
@ -55,6 +77,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The canberra distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testCanberra() : void public function testCanberra() : void
{ {
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
@ -64,6 +91,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The bray-curtis distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testBrayCurtis() : void public function testBrayCurtis() : void
{ {
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
@ -73,6 +105,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The angular distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testAngularSeparation() : void public function testAngularSeparation() : void
{ {
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
@ -82,6 +119,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The hamming distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testHammingDistance() : void public function testHammingDistance() : void
{ {
self::assertEquals( self::assertEquals(
@ -90,6 +132,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox The ulam distance can be calculated
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testUlam(): void public function testUlam(): void
{ {
self::assertEquals( self::assertEquals(
@ -98,6 +145,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
); );
} }
/**
* @testdox Different dimension sizes for the coordinates in the hamming metric throw a InvalidDimensionException
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testInvalidHammingDimension() : void public function testInvalidHammingDimension() : void
{ {
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
@ -105,6 +157,11 @@ class Metrics2DTest extends \PHPUnit\Framework\TestCase
Metrics2D::hamming([1, 1, 1, 1], [0, 1, 0]); Metrics2D::hamming([1, 1, 1, 1], [0, 1, 0]);
} }
/**
* @testdox Different dimension sizes for the coordinates in the ulam metric throw a InvalidDimensionException
* @covers phpOMS\Math\Topology\Metrics2D
* @group framework
*/
public function testInvalidUlamDimension() : void public function testInvalidUlamDimension() : void
{ {
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);

View File

@ -52,7 +52,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox The constant values of the abstract module are overwritten by the extension * @testdox The constant values of the abstract module are overwritten by the extension
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleAbstract<extended>
* @group framework * @group framework
*/ */
public function testConstants() : void public function testConstants() : void
@ -63,7 +63,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox The dependencies of the module can be returned * @testdox The dependencies of the module can be returned
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleAbstract<extended>
* @group framework * @group framework
*/ */
public function testDependencies() : void public function testDependencies() : void
@ -73,7 +73,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox A invalid language or theme returns in an empty localization/language dataset * @testdox A invalid language or theme returns in an empty localization/language dataset
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleAbstract<extended>
* @group framework * @group framework
*/ */
public function testInvalidLocalization() : void public function testInvalidLocalization() : void
@ -83,7 +83,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox The module can automatically generate a json response based on provided data for the frontend * @testdox The module can automatically generate a json response based on provided data for the frontend
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleAbstract<extended>
* @group framework * @group framework
*/ */
public function testFillJson() : void public function testFillJson() : void
@ -106,7 +106,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox The module can automatically generate a json response based on provided data * @testdox The module can automatically generate a json response based on provided data
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleAbstract<extended>
* @group framework * @group framework
*/ */
public function testFillJsonRaw() : void public function testFillJsonRaw() : void

View File

@ -18,6 +18,8 @@ use phpOMS\ApplicationAbstract;
use phpOMS\Dispatcher\Dispatcher; use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Module\ModuleManager; use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter; use phpOMS\Router\WebRouter;
use phpOMS\Message\Http\Request;
use phpOMS\Uri\Http;
require_once __DIR__ . '/../Autoloader.php'; require_once __DIR__ . '/../Autoloader.php';
@ -38,8 +40,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
$this->app->dbPool = $GLOBALS['dbpool']; $this->app->dbPool = $GLOBALS['dbpool'];
$this->app->router = new WebRouter(); $this->app->router = new WebRouter();
$this->app->dispatcher = new Dispatcher($this->app); $this->app->dispatcher = new Dispatcher($this->app);
$this->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules');
$this->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules');
} }
/** /**
@ -95,13 +96,41 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleManager
* @group framework * @group framework
*/ */
public function testActiveModules() : void public function testAllActiveModules() : void
{ {
$active = $this->moduleManager->getActiveModules(); $active = $this->moduleManager->getActiveModules();
self::assertNotEmpty($active); self::assertNotEmpty($active);
} }
/**
* @testdox Modules can be checked to be active
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testActiveModule() : void
{
$active = $this->moduleManager->getActiveModules();
/** @var string $last */
$last = \end($active);
self::assertTrue($this->moduleManager->isActive($last['name']['internal']));
self::assertFalse($this->moduleManager->isActive('Invalid'));
}
/**
* @testdox Modules can be checked to be running
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testRunningModule() : void
{
$module = $this->moduleManager->get('TestModule');
self::assertTrue($this->moduleManager->isRunning('TestModule'));
self::assertFalse($this->moduleManager->isRunning('Invalid'));
}
/** /**
* @testdox All available modules can be returned * @testdox All available modules can be returned
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleManager
@ -114,6 +143,62 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
self::assertNotEmpty($all); self::assertNotEmpty($all);
} }
/**
* @testdox A module can be installed and its status can be changed
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testStatus() : void
{
$this->moduleManager->install('TestModule');
self::assertTrue($this->moduleManager->deactivate('TestModule'));
self::assertFalse($this->moduleManager->isActive('TestModule'));
self::assertTrue($this->moduleManager->activate('TestModule'));
self::assertTrue($this->moduleManager->isActive('TestModule'));
}
/**
* @testdox A module can be re-initialized
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testReInit() : void
{
$this->moduleManager->reInit('TestModule');
self::assertTrue($this->moduleManager->isActive('TestModule'));
}
/**
* @testdox A module is automatically loaded for its URIs
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testRequestLoad() : void
{
$request = new Request(new Http('http://127.0.0.1/en/backend/testmodule'));
$request->createRequestHashs(2);
$loaded = $this->moduleManager->getUriLoad($request);
$found = false;
foreach ($loaded[4] as $module) {
if ($module['module_load_file'] === 'TestModule') {
$found = true;
break;
}
}
self::assertTrue($found);
self::assertGreaterThan(0, \count($this->moduleManager->getLanguageFiles($request)));
self::assertTrue(\in_array('TestModule', $this->moduleManager->getRoutedModules($request)));
$this->moduleManager->initRequestModules($request);
self::assertTrue($this->moduleManager->isRunning('TestModule'));
}
/** /**
* @testdox Installed modules can be returned * @testdox Installed modules can be returned
* @covers phpOMS\Module\ModuleManager * @covers phpOMS\Module\ModuleManager
@ -137,4 +222,17 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf('\Modules\Admin\Controller\ApiController', $this->moduleManager->get('Admin')); self::assertInstanceOf('\Modules\Admin\Controller\ApiController', $this->moduleManager->get('Admin'));
} }
/**
* @testdox A module can be uninstalled
* @covers phpOMS\Module\ModuleManager
* @group framework
*/
public function testUninstall() : void
{
$this->moduleManager->uninstall('TestModule');
self::assertFalse($this->moduleManager->uninstall('TestModule'));
self::assertFalse($this->moduleManager->isActive('TestModule'));
self::assertFalse($this->moduleManager->isRunning('TestModule'));
}
} }