Tests, docblocks & improvements

This commit is contained in:
Dennis Eichhorn 2018-03-03 11:15:34 +01:00
parent 24252655eb
commit de6120b267
36 changed files with 474 additions and 120 deletions

View File

@ -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;
}

View File

@ -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.

View File

@ -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) {

View File

@ -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
{
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()) {

View File

@ -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);
}

View File

@ -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 = [];

View File

@ -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
{
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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)
{
}
}

View File

@ -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'));

View File

@ -0,0 +1,24 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\DataStorage\Database\Exception;
use phpOMS\DataStorage\Database\Exception\InvalidDatabaseTypeException;
class InvalidDatabaseTypeExceptionTest extends \PHPUnit\Framework\TestCase
{
public function testException()
{
self::assertInstanceOf(\InvalidArgumentException::class, new InvalidDatabaseTypeException(''));
}
}

View File

@ -39,5 +39,26 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
$vec = new Vector();
$vec->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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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));

View File

@ -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
*/

View File

@ -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) <Dennis Eichhorn> 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
*/

View File

@ -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']);
}
}

View File

@ -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();

View File

@ -0,0 +1,26 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
namespace phpOMS\tests\Module;
require_once __DIR__ . '/../Autoloader.php';
use phpOMS\Module\PackageManager;
class PackageManagerTest extends \PHPUnit\Framework\TestCase
{
public function testPackage()
{
self::markTestIncomplete();
}
}

View File

@ -1,6 +1,6 @@
<?php
function hasDeprecated()
{
return eval('1 === 1');
}
<?php
function hasDeprecated()
{
return eval('1 === 1');
}

View File

@ -1,6 +1,6 @@
<?php
function has𠀊Unicode()
{
return true;
}
<?php
function has𠀊Unicode()
{
return true;
}

View File

@ -1,6 +1,6 @@
<?php
function noDeprecated()
{
return is_string('');
}
<?php
function noDeprecated()
{
return is_string('');
}

View File

@ -1,6 +1,6 @@
<?php
function noUnicode()
{
return true;
}
<?php
function noUnicode()
{
return true;
}

View File

@ -78,9 +78,11 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
],
],
2 => '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;'], ';', '"', '\\'));