diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index 77d35056f..1f0675742 100644 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -76,7 +76,7 @@ class FileCache extends ConnectionAbstract /** * {@inheritdoc} */ - public function connect(array $dbdata) /* : void */ + public function connect(array $data) /* : void */ { $this->status = CacheStatus::ACTIVE; } diff --git a/DataStorage/DataStorageConnectionInterface.php b/DataStorage/DataStorageConnectionInterface.php index c15fb1283..3ac8a25ea 100644 --- a/DataStorage/DataStorageConnectionInterface.php +++ b/DataStorage/DataStorageConnectionInterface.php @@ -30,7 +30,7 @@ interface DataStorageConnectionInterface * * Overwrites current connection if existing * - * @param string[] $dbdata the basic datastorage information for establishing a connection + * @param string[] $data the basic datastorage information for establishing a connection * * @return void * @@ -38,7 +38,7 @@ interface DataStorageConnectionInterface * * @since 1.0.0 */ - public function connect(array $dbdata); /* : void */ + public function connect(array $data); /* : void */ /** * Get the datastorage type. diff --git a/Math/Matrix/CholeskyDecomposition.php b/Math/Matrix/CholeskyDecomposition.php index 8c0f9ad8b..995b30799 100644 --- a/Math/Matrix/CholeskyDecomposition.php +++ b/Math/Matrix/CholeskyDecomposition.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -14,18 +14,49 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; +use phpOMS\Math\Matrix\Exception\InvalidDimensionException; + +/** + * Cholesky decomposition + * + * @package phpOMS\Math\Matrix + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class CholeskyDecomposition { + /** + * L matrix. + * + * @var array + * @since 1.0.0 + */ private $L = []; + /** + * Dimension of L + * + * @var int + * @since 1.0.0 + */ private $m = 0; /** - * Is symmetric positive definite + * Is symmetric positiv definite + * + * @var bool + * @since 1.0.0 */ private $isSpd = true; - // see http://www.aip.de/groups/soe/local/numres/bookfpdf/f2-9.pdf + /** + * Constructor. + * + * @param Matrix $M Matrix + * + * @since 1.0.0 + */ public function __construct(Matrix $M) { $this->L = $M->toArray(); @@ -56,11 +87,25 @@ class CholeskyDecomposition } } + /** + * Is matrix symmetric positiv definite. + * + * @return bool + * + * @since 1.0.0 + */ public function isSpd() : bool { return $this->isSpd; } + /** + * Get L matrix + * + * @return Matrix + * + * @since 1.0.0 + */ public function getL() : Matrix { $matrix = new Matrix(); @@ -69,10 +114,19 @@ class CholeskyDecomposition return $matrix; } + /** + * Solve Ax = b + * + * @param Matrix $B Matrix + * + * @return Matrix + * + * @since 1.0.0 + */ public function solve(Matrix $B) : Matrix { if ($B->getM() !== $this->m) { - throw new \Exception(); + throw new InvalidDimensionException((string) $B->getM()); } if (!$this->isSpd) { diff --git a/Math/Matrix/EigenvalueDecomposition.php b/Math/Matrix/EigenvalueDecomposition.php index b2f757220..484880ad1 100644 --- a/Math/Matrix/EigenvalueDecomposition.php +++ b/Math/Matrix/EigenvalueDecomposition.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -14,6 +14,14 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; +/** + * Eigenvalue decomposition + * + * @package phpOMS\Math\Matrix + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class EigenValueDecomposition { } diff --git a/Math/Matrix/Exception/InvalidDimensionException.php b/Math/Matrix/Exception/InvalidDimensionException.php index 4b163d17f..2d5bd04c0 100644 --- a/Math/Matrix/Exception/InvalidDimensionException.php +++ b/Math/Matrix/Exception/InvalidDimensionException.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix\Exception * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\Math\Matrix\Exception; /** * Zero devision exception. * - * @package Framework + * @package phpOMS\Math\Matrix\Exception * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Matrix/IdentityMatrix.php b/Math/Matrix/IdentityMatrix.php index 0fca99f55..36146a457 100644 --- a/Math/Matrix/IdentityMatrix.php +++ b/Math/Matrix/IdentityMatrix.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -15,9 +15,9 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; /** - * Matrix class + * Identity Matrix * - * @package Framework + * @package phpOMS\Math\Matrix * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Matrix/InverseType.php b/Math/Matrix/InverseType.php index 5e2841511..096666531 100644 --- a/Math/Matrix/InverseType.php +++ b/Math/Matrix/InverseType.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ use phpOMS\Stdlib\Base\Enum; /** * Inverse type enum. * - * @package Framework + * @package phpOMS\Math\Matrix * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php index 1998e5fc7..fb160b347 100644 --- a/Math/Matrix/LUDecomposition.php +++ b/Math/Matrix/LUDecomposition.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -14,17 +14,65 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; +use phpOMS\Math\Matrix\Exception\InvalidDimensionException; + +/** + * LU decomposition + * + * @package phpOMS\Math\Matrix + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class LUDecomposition { + /** + * LU matrix. + * + * @var array + * @since 1.0.0 + */ private $LU = []; + /** + * Dimension m + * + * @var int + * @since 1.0.0 + */ private $m = 0; + + /** + * Dimension n + * + * @var int + * @since 1.0.0 + */ private $n = 0; + /** + * Pivot sign + * + * @var int + * @since 1.0.0 + */ private $pivSign = 1; + /** + * Pivot + * + * @var array + * @since 1.0.0 + */ private $piv = []; + /** + * Constructor. + * + * @param Matrix $M Matrix + * + * @since 1.0.0 + */ public function __construct(Matrix $M) { $this->LU = $M->toArray(); @@ -82,6 +130,13 @@ class LUDecomposition } } + /** + * Get L matrix + * + * @return Matrix + * + * @since 1.0.0 + */ public function getL() : Matrix { $L = [[]]; @@ -104,6 +159,13 @@ class LUDecomposition return $matrix; } + /** + * Get U matrix + * + * @return Matrix + * + * @since 1.0.0 + */ public function getU() : Matrix { $U = [[]]; @@ -124,11 +186,25 @@ class LUDecomposition return $matrix; } - public function getPivot() + /** + * Get pivot + * + * @return array + * + * @since 1.0.0 + */ + public function getPivot() : array { return $this->piv; } + /** + * Is matrix nonsingular + * + * @return bool + * + * @since 1.0.0 + */ public function isNonsingular() : bool { for ($j = 0; $j < $this->n; ++$j) { @@ -140,6 +216,13 @@ class LUDecomposition return true; } + /** + * Get determinant + * + * @return mixed + * + * @since 1.0.0 + */ public function det() { $d = $this->pivSign; @@ -150,10 +233,19 @@ class LUDecomposition return $d; } + /** + * Solve Ax = b + * + * @param Matrix $B Matrix + * + * @return Matrix + * + * @since 1.0.0 + */ public function solve(Matrix $B) : Matrix { if ($B->getM() !== $this->m) { - throw new \Exception(); + throw new InvalidDimensionException((string) $B->getM()); } if (!$this->isNonsingular()) { diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index b137d13fe..6735aed75 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -91,7 +91,7 @@ class Matrix implements \ArrayAccess, \Iterator */ public function set(int $m, int $n, $value) /* : void */ { - if (!isset($this->matrix[$m][$n])) { + if (!isset($this->matrix[$m], $this->matrix[$m][$n])) { throw new InvalidDimensionException($m . 'x' . $n); } @@ -112,7 +112,7 @@ class Matrix implements \ArrayAccess, \Iterator */ public function get(int $m, int $n) { - if (!isset($this->matrix[$m][$n])) { + if (!isset($this->matrix[$m], $this->matrix[$m][$n])) { throw new InvalidDimensionException($m . 'x' . $n); } @@ -203,9 +203,9 @@ class Matrix implements \ArrayAccess, \Iterator */ public function sub($value) : Matrix { - if ($value instanceOf Matrix) { - return $this->add($this->mult(-1)); - } elseif (is_scalar($value)) { + if ($value instanceof Matrix) { + return $this->add($value->mult(-1)); + } elseif (is_numeric($value)) { return $this->add(-$value); } @@ -225,9 +225,9 @@ class Matrix implements \ArrayAccess, \Iterator */ public function add($value) : Matrix { - if ($value instanceOf Matrix) { + if ($value instanceof Matrix) { return $this->addMatrix($value); - } elseif (is_scalar($value)) { + } elseif (is_numeric($value)) { return $this->addScalar($value); } @@ -330,9 +330,9 @@ class Matrix implements \ArrayAccess, \Iterator */ public function mult($value) : Matrix { - if ($value instanceOf Matrix) { + if ($value instanceof Matrix) { return $this->multMatrix($value); - } elseif (is_scalar($value)) { + } elseif (is_numeric($value)) { return $this->multScalar($value); } diff --git a/Math/Matrix/QRDecomposition.php b/Math/Matrix/QRDecomposition.php index 714284f30..9b8bb5978 100644 --- a/Math/Matrix/QRDecomposition.php +++ b/Math/Matrix/QRDecomposition.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -14,6 +14,14 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; +/** + * QR decomposition + * + * @package phpOMS\Math\Matrix + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class QRDecomposition { private $QR = []; diff --git a/Math/Matrix/SingularValueDecomposition.php b/Math/Matrix/SingularValueDecomposition.php index 3fa6c7447..417f08a8e 100644 --- a/Math/Matrix/SingularValueDecomposition.php +++ b/Math/Matrix/SingularValueDecomposition.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -14,6 +14,14 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; +/** + * Singular value decomposition + * + * @package phpOMS\Math\Matrix + * @license OMS License 1.0 + * @link http://website.orange-management.de + * @since 1.0.0 + */ class SingularValueDecomposition { } diff --git a/Math/Matrix/Vector.php b/Math/Matrix/Vector.php index 9e3a666fc..1195057f9 100644 --- a/Math/Matrix/Vector.php +++ b/Math/Matrix/Vector.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -15,9 +15,9 @@ declare(strict_types=1); namespace phpOMS\Math\Matrix; /** - * Matrix class + * Vector class * - * @package Framework + * @package phpOMS\Math\Matrix * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index d3b9d3cbf..a19be69ca 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Statistic * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -20,7 +20,7 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Average class. * - * @package Framework + * @package phpOMS\Math\Statistic * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Statistic/Basic.php b/Math/Statistic/Basic.php index c1905a96c..c7222ccaa 100644 --- a/Math/Statistic/Basic.php +++ b/Math/Statistic/Basic.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Statistic * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\Math\Statistic; /** * Basic statistic functions. * - * @package Framework + * @package phpOMS\Math\Statistic * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Statistic/Correlation.php b/Math/Statistic/Correlation.php index 578356336..1e750fe9f 100644 --- a/Math/Statistic/Correlation.php +++ b/Math/Statistic/Correlation.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Statistic * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\Math\Statistic; /** * Correlation. * - * @package Framework + * @package phpOMS\Math\Statistic * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/Math/Statistic/MeasureOfDispersion.php b/Math/Statistic/MeasureOfDispersion.php index 36c6f8d75..e60b22780 100644 --- a/Math/Statistic/MeasureOfDispersion.php +++ b/Math/Statistic/MeasureOfDispersion.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\Math\Statistic * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -20,7 +20,7 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Measure of dispersion. * - * @package Framework + * @package phpOMS\Math\Statistic * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 @@ -66,7 +66,7 @@ class MeasureOfDispersion { $mean = $mean !== null ? $mean : Average::arithmeticMean($values); - if ($mean === 0) { + if ($mean === 0.0) { throw new ZeroDevisionException(); } diff --git a/Message/Http/Request.php b/Message/Http/Request.php index b92895263..ea0741cbd 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -450,4 +450,30 @@ class Request extends RequestAbstract return $this->method; } + + /** + * Perform rest request + * + * @return string + * + * @since 1.0.0 + */ + public function rest() : string + { + return Rest::request($this); + } + + /** + * {@inheritdoc} + */ + public function __toString() : string + { + if ($this->getMethod() === RequestMethod::GET && !empty($this->data)) { + return $this->uri->__toString() + . (parse_url($this->uri->__toString(), PHP_URL_QUERY) ? '&' : '?') + . http_build_query($this->data); + } + + return parent::__toString(); + } } diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index 06e07a8e7..dfb5aba24 100644 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -39,22 +39,26 @@ class Rest $curl = curl_init(); switch ($request->getMethod()) { - case RequestMethod::POST: - curl_setopt($curl, CURLOPT_POST, 1); - - if ($request->getData() !== null) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData()); - } - break; case RequestMethod::PUT: - curl_setopt($curl, CURLOPT_PUT, 1); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); + break; + case RequestMethod::DELETE: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } - curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($curl, CURLOPT_USERPWD, "username:password"); + if ($request->getMethod() !== RequestMethod::GET) { + curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_URL, $request->getUri()->__toString()); + if ($request->getData() !== null) { + curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData()); + } + } + + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($curl, CURLOPT_USERPWD, 'username:password'); + + curl_setopt($curl, CURLOPT_URL, $request->__toString()); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index e6aeb4b29..add7177be 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -234,10 +234,6 @@ class ArrayUtils case 'string': $str .= $key . ' => \'' . $value . '\', '; break; - case 'object': - $str .= $key . ' => ' . get_class($value['default']) . '()'; - // TODO: implement object with parameters -> Reflection - break; case 'boolean': $str .= $key . ' => ' . ($value['default'] ? 'true' : 'false') . ', '; break; diff --git a/Utils/RnG/File.php b/Utils/RnG/File.php index 6aa3baff8..6d7d2c162 100644 --- a/Utils/RnG/File.php +++ b/Utils/RnG/File.php @@ -32,17 +32,17 @@ class File * @since 1.0.0 */ private static $extensions = [ - ['exe', null], ['dat', null], ['txt', null], ['csv', 'txt'], ['doc', null], ['docx', 'doc'], - ['mp3', null], ['mp4', null], ['avi', null], ['mpeg', null], ['wmv', null], ['ppt', null], - ['xls', null], ['xlsx', 'xls'], ['xlsxm', 'xls'], ['php', null], ['html', null], ['tex', null], - ['js', null], ['c', null], ['cpp', null], ['h', null], ['res', null], ['ico', null], - ['jpg', null], ['png', null], ['gif', null], ['bmp', null], ['ttf', null], ['zip', null], - ['rar', null], ['7z', null], ['tar', 'gz'], ['gz', null], ['gz', null], ['sh', null], - ['bat', null], ['iso', null], ['css', null], ['json', null], ['ini', null], ['psd', null], - ['pptx', 'ppt'], ['xml', null], ['dll', null], ['wav', null], ['wma', null], ['vb', null], - ['tmp', null], ['tif', null], ['sql', null], ['swf', null], ['svg', null], ['rpm', null], - ['rss', null], ['pkg', null], ['pdf', null], ['mpg', null], ['mov', null], ['jar', null], - ['flv', null], ['fla', null], ['deb', null], ['py', null], ['pl', null], + ['exe'], ['dat'], ['txt'], ['csv', 'txt'], ['doc'], ['docx', 'doc'], + ['mp3'], ['mp4'], ['avi'], ['mpeg'], ['wmv'], ['ppt'], + ['xls'], ['xlsx', 'xls'], ['xlsxm', 'xls'], ['php'], ['html'], ['tex'], + ['js'], ['c'], ['cpp'], ['h'], ['res'], ['ico'], + ['jpg'], ['png'], ['gif'], ['bmp'], ['ttf'], ['zip'], + ['rar'], ['7z'], ['tar', 'gz'], ['gz'], ['gz'], ['sh'], + ['bat'], ['iso'], ['css'], ['json'], ['ini'], ['psd'], + ['pptx', 'ppt'], ['xml'], ['dll'], ['wav'], ['wma'], ['vb'], + ['tmp'], ['tif'], ['sql'], ['swf'], ['svg'], ['rpm'], + ['rss'], ['pkg'], ['pdf'], ['mpg'], ['mov'], ['jar'], + ['flv'], ['fla'], ['deb'], ['py'], ['pl'], ]; /** @@ -71,16 +71,4 @@ class File return $source[$key][0]; } - - public static function generateFileName() - { - } - - public static function generateFileVirtual($path, $name = null, $size = [0, 1000000], $extension = null) - { - } - - public static function generateFile($path, $name = null, $size = [0, 1000000], $extension = null) - { - } } diff --git a/tests/DataStorage/Cache/CachePoolTest.php b/tests/DataStorage/Cache/CachePoolTest.php index 3badb8422..befa2d796 100644 --- a/tests/DataStorage/Cache/CachePoolTest.php +++ b/tests/DataStorage/Cache/CachePoolTest.php @@ -33,7 +33,9 @@ class CachePoolTest extends \PHPUnit\Framework\TestCase self::assertTrue($pool->add('test', new FileCache(__DIR__))); self::assertFalse($pool->add('test', new FileCache(__DIR__))); self::assertInstanceOf('\phpOMS\DataStorage\Cache\Connection\ConnectionInterface', $pool->get('test')); + self::assertInstanceOf('\phpOMS\DataStorage\Cache\Connection\ConnectionInterface', $pool->get()); self::assertTrue($pool->create('abc', ['type' => 'file', 'path' => __DIR__])); + self::assertFalse($pool->create('abc', ['type' => 'file', 'path' => __DIR__])); self::assertInstanceOf('\phpOMS\DataStorage\Cache\Connection\ConnectionInterface', $pool->get('abc')); self::assertTrue($pool->remove('abc')); self::assertEquals(null, $pool->get('abc')); diff --git a/tests/DataStorage/Database/Exception/InvalidDatabaseTypeExceptionTest.php b/tests/DataStorage/Database/Exception/InvalidDatabaseTypeExceptionTest.php new file mode 100644 index 000000000..8a05feb9a --- /dev/null +++ b/tests/DataStorage/Database/Exception/InvalidDatabaseTypeExceptionTest.php @@ -0,0 +1,24 @@ +setMatrix([[40], [49], [28]]); self::assertEquals([[1], [2], [3]], $cholesky->solve($vec)->toArray(), '', 0.2); + + self::assertTrue($cholesky->isSpd()); + } + + /** + * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException + */ + public function testInvalidDimension() + { + $A = new Matrix(); + $A->setMatrix([ + [25, 15, -5], + [15, 17, 0], + [-5, 0, 11], + ]); + + $cholesky = new CholeskyDecomposition($A); + + $vec = new Vector(); + $vec->setMatrix([[40], [49]]); + $cholesky->solve($vec); } } diff --git a/tests/Math/Matrix/LUDecompositionTest.php b/tests/Math/Matrix/LUDecompositionTest.php index d9f69505c..4ac43988a 100644 --- a/tests/Math/Matrix/LUDecompositionTest.php +++ b/tests/Math/Matrix/LUDecompositionTest.php @@ -45,5 +45,25 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase $vec = new Vector(); $vec->setMatrix([[40], [49], [28]]); self::assertEquals([[1], [2], [3]], $lu->solve($vec)->toArray(), '', 0.2); + self::assertEquals([0, 1, 2], $lu->getPivot()); + } + + /** + * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException + */ + public function testInvalidDimension() + { + $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]]); + + $lu->solve($vec); } } diff --git a/tests/Math/Matrix/MatrixTest.php b/tests/Math/Matrix/MatrixTest.php index 2658bc9b1..2e82aa3bb 100644 --- a/tests/Math/Matrix/MatrixTest.php +++ b/tests/Math/Matrix/MatrixTest.php @@ -159,7 +159,7 @@ class MatrixTest extends \PHPUnit\Framework\TestCase /** * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException */ - public function invalidSetIndexException() + public function testInvalidSetIndexException() { $id = new Matrix(); $id->setMatrix([ @@ -172,7 +172,7 @@ class MatrixTest extends \PHPUnit\Framework\TestCase /** * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException */ - public function invalidGetIndexException() + public function testInvalidGetIndexException() { $id = new Matrix(); $id->setMatrix([ @@ -185,7 +185,7 @@ class MatrixTest extends \PHPUnit\Framework\TestCase /** * @expectedException \InvalidArgumentException */ - public function invalidSub() + public function testInvalidSub() { $id = new Matrix(); $id->setMatrix([ @@ -193,13 +193,13 @@ class MatrixTest extends \PHPUnit\Framework\TestCase [0, 1], ]); - $id->sub([]); + $id->sub(true); } /** * @expectedException \InvalidArgumentException */ - public function invalidAdd() + public function testInvalidAdd() { $id = new Matrix(); $id->setMatrix([ @@ -207,13 +207,13 @@ class MatrixTest extends \PHPUnit\Framework\TestCase [0, 1], ]); - $id->add([]); + $id->add(true); } /** * @expectedException \InvalidArgumentException */ - public function invalidMult() + public function testInvalidMult() { $id = new Matrix(); $id->setMatrix([ @@ -221,19 +221,19 @@ class MatrixTest extends \PHPUnit\Framework\TestCase [0, 1], ]); - $id->mult([]); + $id->mult(true); } /** * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException */ - public function invalidDimensionAdd() + public function testInvalidDimensionAdd() { $A = new Matrix(); $A->setMatrix([[1, 2], [3, 4]]); $B = new Matrix(); - $B->setMatrix([[1, 2], [3, 4], [5, 6]]); + $B->setMatrix([[1, 2, 1], [3, 4, 1], [5, 6, 1]]); $A->add($B); } @@ -241,13 +241,13 @@ class MatrixTest extends \PHPUnit\Framework\TestCase /** * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException */ - public function invalidDimensionSub() + public function testInvalidDimensionSub() { $A = new Matrix(); $A->setMatrix([[1, 2], [3, 4]]); $B = new Matrix(); - $B->setMatrix([[1, 2], [3, 4], [5, 6]]); + $B->setMatrix([[1, 2, 1], [3, 4, 1], [5, 6, 1]]); $A->sub($B); } @@ -255,13 +255,13 @@ class MatrixTest extends \PHPUnit\Framework\TestCase /** * @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException */ - public function invalidDimensionMult() + public function testInvalidDimensionMult() { $A = new Matrix(); $A->setMatrix([[1, 2], [3, 4]]); $B = new Matrix(); - $B->setMatrix([[1, 2], [3, 4], [5, 6]]); + $B->setMatrix([[1, 2, 1], [3, 4, 1], [5, 6, 1]]); $A->mult($B); } diff --git a/tests/Math/Number/IntegerTest.php b/tests/Math/Number/IntegerTest.php index 973bdfb3b..b1eb89d83 100644 --- a/tests/Math/Number/IntegerTest.php +++ b/tests/Math/Number/IntegerTest.php @@ -24,6 +24,7 @@ class IntegerTest extends \PHPUnit\Framework\TestCase self::assertFalse(Integer::isInteger('3')); self::assertArraySubset([2, 2, 5, 5], Integer::trialFactorization(100)); + self::assertArraySubset([2], Integer::trialFactorization(2)); self::assertEquals([], Integer::trialFactorization(1)); self::assertEquals(101, Integer::pollardsRho(10403, 2, 1, 2, 2)); diff --git a/tests/Math/Statistic/MeasureOfDispersionTest.php b/tests/Math/Statistic/MeasureOfDispersionTest.php index 2308f1a0e..ed10fcae6 100644 --- a/tests/Math/Statistic/MeasureOfDispersionTest.php +++ b/tests/Math/Statistic/MeasureOfDispersionTest.php @@ -56,6 +56,14 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase self::assertEquals(0.5400, MeasureOfDispersion::empiricalVariationCoefficient([1, 2, 3, 4, 5, 6, 7]), '', 0.01); } + /** + * @expectedException phpOMS\Math\Exception\ZeroDevisionException + */ + public function testInvalidEmpiricalVariationCoefficient() + { + MeasureOfDispersion::empiricalVariationCoefficient([1, 2, 3, 4, 5, 6, 7], 0); + } + /** * @expectedException phpOMS\Math\Exception\ZeroDevisionException */ diff --git a/tests/Message/Http/RequestTest.php b/tests/Message/Http/RequestTest.php index e7f48ecb6..6f5b74f90 100644 --- a/tests/Message/Http/RequestTest.php +++ b/tests/Message/Http/RequestTest.php @@ -77,8 +77,6 @@ class RequestTest extends \PHPUnit\Framework\TestCase self::assertEquals('http://www.google.com/test/path', $request->getUri()->__toString()); $request->createRequestHashs(0); - self::assertEquals('http://www.google.com/test/path', $request->__toString()); - self::assertEquals([ 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', '328413d996ab9b79af9d4098af3a65b885c4ca64' @@ -100,6 +98,34 @@ class RequestTest extends \PHPUnit\Framework\TestCase self::assertEquals('http://www.google.com/test/path2', $request->__toString()); } + public function testToString() + { + $request = new Request(new Http('http://www.google.com/test/path')); + self::assertEquals('http://www.google.com/test/path', $request->__toString()); + + $request->setData('test', 'data'); + $request->setData('test2', 3); + self::assertEquals('http://www.google.com/test/path?test=data&test2=3', $request->__toString()); + + $request = new Request(new Http('http://www.google.com/test/path?test=var')); + self::assertEquals('http://www.google.com/test/path?test=var', $request->__toString()); + + $request->setData('test', 'data'); + $request->setData('test2', 3); + self::assertEquals('http://www.google.com/test/path?test=var&test=data&test2=3', $request->__toString()); + } + + public function testRestRequest() + { + $request = new Request(new Http('http://orange-management.de/phpOMS/LICENSE.txt')); + $request->setMethod(RequestMethod::GET); + + self::assertEquals( + "The OMS License 1.0\n\nCopyright (c) All Rights Reserved\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.", + $request->rest() + ); + } + /** * @expectedException \phpOMS\Stdlib\Base\Exception\InvalidEnumValue */ diff --git a/tests/Message/Http/RestTest.php b/tests/Message/Http/RestTest.php index ef65c1375..2d7a4192c 100644 --- a/tests/Message/Http/RestTest.php +++ b/tests/Message/Http/RestTest.php @@ -31,4 +31,36 @@ class RestTest extends \PHPUnit\Framework\TestCase Rest::request($request) ); } + + public function testPost() + { + $request = new Request(new Http('http://httpbin.org/post')); + $request->setMethod(RequestMethod::POST); + self::assertTrue($request->setData('pdata', 'abc')); + self::assertEquals('abc', json_decode(REST::request($request), true)['form']['pdata']); + } + + public function testPut() + { + $request = new Request(new Http('http://httpbin.org/put')); + $request->setMethod(RequestMethod::PUT); + self::assertTrue($request->setData('pdata', 'abc')); + self::assertEquals('abc', json_decode(REST::request($request), true)['form']['pdata']); + } + + public function testDelete() + { + $request = new Request(new Http('http://httpbin.org/delete')); + $request->setMethod(RequestMethod::DELETE); + self::assertTrue($request->setData('ddata', 'abc')); + self::assertEquals('abc', json_decode(REST::request($request), true)['form']['ddata']); + } + + public function testGet() + { + $request = new Request(new Http('http://httpbin.org/get')); + $request->setMethod(RequestMethod::GET); + self::assertTrue($request->setData('gdata', 'abc')); + self::assertEquals('abc', json_decode(REST::request($request), true)['args']['gdata']); + } } diff --git a/tests/Module/ModuleManagerTest.php b/tests/Module/ModuleManagerTest.php index 9e4848462..d7dc616e7 100644 --- a/tests/Module/ModuleManagerTest.php +++ b/tests/Module/ModuleManagerTest.php @@ -58,6 +58,14 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase self::assertInstanceOf('\phpOMS\Module\NullModule', $moduleManager->get('doesNotExist2')); } + public function testUnknwonModuleModification() + { + $moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules'); + + self::assertFalse($moduleManager->activate('randomErrorTest1')); + self::assertFalse($moduleManager->deactivate('randomErrorTest1')); + } + public function testGetSet() { $this->app->router = new Router(); diff --git a/tests/Module/PackageManagerTest.php b/tests/Module/PackageManagerTest.php new file mode 100644 index 000000000..7467bcde5 --- /dev/null +++ b/tests/Module/PackageManagerTest.php @@ -0,0 +1,26 @@ + '2a', + 3 => false, + 'c' => null ]; - $expected_str = "['a' => ['aa' => 1, 'ab' => [0 => 'aba', 1 => 'ab0', ], ], 2 => '2a', ]"; + $expected_str = "['a' => ['aa' => 1, 'ab' => [0 => 'aba', 1 => 'ab0', ], ], 2 => '2a', 3 => false, 'c' => null, ]"; self::assertEquals($expected_str, ArrayUtils::stringify($expected)); self::assertEquals('2;3;1;"""Text;"' . "\n", ArrayUtils::arrayToCsv(['a' => 2, 3, 1, '"Text;'], ';', '"', '\\'));