mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
75% code coverage
This commit is contained in:
parent
64c9cda54e
commit
2023b9ab75
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package phpOMS\DataStorage\Session
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\Session;
|
||||
|
||||
/**
|
||||
* Console session class.
|
||||
*
|
||||
* @package phpOMS\DataStorage\Session
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ConsoleSession implements SessionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Session ID.
|
||||
*
|
||||
* @var string|int|null
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $sid = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|int|null $sid Session id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct($sid = null)
|
||||
{
|
||||
if ($sid !== null) {
|
||||
$this->sid = $sid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = true) : bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($key) : bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSID()
|
||||
{
|
||||
return $this->sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSID($sid) : void
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save() : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lock() : void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package phpOMS\DataStorage\Session
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\Session;
|
||||
|
||||
/**
|
||||
* Socket session class.
|
||||
*
|
||||
* @package phpOMS\DataStorage\Session
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SocketSession implements SessionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Session ID.
|
||||
*
|
||||
* @var string|int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $sid = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|int|null $sid Session id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct($sid = null)
|
||||
{
|
||||
if ($sid !== null) {
|
||||
$this->sid = $sid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = true) : bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($key) : bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSID()
|
||||
{
|
||||
return $this->sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSID($sid) : void
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save() : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function lock() : void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package phpOMS\DataStorage\Web
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace phpOMS\DataStorage\Web;
|
||||
|
||||
use phpOMs\DataStorage\Database\Query\Builder as DatabaseQueryBuilder;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Message\Http\Rest;
|
||||
use phpOMS\Uri\Http;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
*
|
||||
* @package phpOMS\DataStorage\Web
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Builder
|
||||
{
|
||||
|
||||
private function download($uri)
|
||||
{
|
||||
$finder = [];
|
||||
$l11n = new Localization();
|
||||
|
||||
foreach ($this->from as $from) {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML(Rest::request($l11n, new Http($from)));
|
||||
$finder[$from] = new \DomXPath($doc);
|
||||
}
|
||||
|
||||
return $finder;
|
||||
}
|
||||
|
||||
public function get(string $xpath)
|
||||
{
|
||||
$nodes = $finder->query($xpath);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$finder = $this->download();
|
||||
$result = [];
|
||||
$table = null;
|
||||
|
||||
foreach ($this->wheres as $column => $where) {
|
||||
if ($column === 'xpath') {
|
||||
$table = $this->createTable($finder->query($where['value']));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->columns as $column) {
|
||||
}
|
||||
}
|
||||
|
||||
private function createTable($node) : array
|
||||
{
|
||||
if (\strtolower($node->tagName) === 'table') {
|
||||
return $this->createTableFromTable();
|
||||
} elseif (\strtolower($node->tagName) === 'li') {
|
||||
return $this->createTableFromList();
|
||||
} else {
|
||||
return $this->createTableFromContent();
|
||||
}
|
||||
}
|
||||
|
||||
private function createTableFromTable($node) : array
|
||||
{
|
||||
// todo: get header either thead or <th> (either first row or first column)
|
||||
|
||||
// todo: get rest except tfoot
|
||||
|
||||
// find first unique column and define as additional id (in addition to row number)
|
||||
}
|
||||
|
||||
private function createTableFromList($node) : array
|
||||
{
|
||||
$table = [];
|
||||
$children = $node->childNodes;
|
||||
|
||||
foreach ($children as $child) {
|
||||
$table[] = $child->asXML();
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
private function createTableFromContent($node) : array
|
||||
{
|
||||
return [$node->asXML()];
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ final class LUDecomposition
|
|||
for ($i = 0; $i < $this->n; ++$i) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($i <= $j) {
|
||||
$U[$i][$j] = $this->LU[$i][$j];
|
||||
$U[$i][$j] = $this->LU[$i][$j] ?? 0;
|
||||
} else {
|
||||
$U[$i][$j] = 0.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -552,10 +552,6 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
$nDim = $matrix->getN();
|
||||
$mDim = $matrix->getM();
|
||||
|
||||
if ($this->n !== $mDim) {
|
||||
throw new InvalidDimensionException($mDim . 'x' . $nDim);
|
||||
}
|
||||
|
||||
$matrixArr = $matrix->getMatrix();
|
||||
$newMatrix = new Matrix($this->m, $nDim);
|
||||
$newMatrixArr = $newMatrix->getMatrix();
|
||||
|
|
@ -565,7 +561,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
$temp = 0;
|
||||
|
||||
for ($j = 0; $j < $mDim; ++$j) { // Row of $matrix
|
||||
$temp += $this->matrix[$i][$j] * $matrixArr[$j][$c];
|
||||
$temp += ($this->matrix[$i][$j] ?? 0) * ($matrixArr[$j][$c] ?? 0);
|
||||
}
|
||||
|
||||
$newMatrixArr[$i][$c] = $temp;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ final class Average
|
|||
}
|
||||
|
||||
/**
|
||||
* Moving average of dataset
|
||||
* Moving average of dataset (SMA)
|
||||
*
|
||||
* @param array<int, float|int> $x Dataset
|
||||
* @param int $order Periods to use for average
|
||||
|
|
@ -84,11 +84,11 @@ final class Average
|
|||
*/
|
||||
public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array
|
||||
{
|
||||
$periods = (int) ($order / 2);
|
||||
$periods = (int) ($order / ($symmetric ? 2 : 1));
|
||||
$count = \count($x) - ($symmetric ? $periods : 0);
|
||||
$avg = [];
|
||||
|
||||
for ($i = $periods; $i < $count; ++$i) {
|
||||
for ($i = $periods - 1; $i < $count; ++$i) {
|
||||
$avg[] = self::movingAverage($x, $i, $order, $weight, $symmetric);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ final class Average
|
|||
}
|
||||
|
||||
/**
|
||||
* Moving average of element in dataset
|
||||
* Moving average of element in dataset (SMA)
|
||||
*
|
||||
* @param array<int, float|int> $x Dataset
|
||||
* @param int $t Current period
|
||||
|
|
@ -112,16 +112,16 @@ final class Average
|
|||
*/
|
||||
public static function movingAverage(array $x, int $t, int $order, array $weight = null, bool $symmetric = false) : float
|
||||
{
|
||||
$periods = (int) ($order / 2);
|
||||
$periods = (int) ($order / ($symmetric ? 2 : 1));
|
||||
$count = \count($x);
|
||||
|
||||
if ($t < $periods || ($count < $periods) || ($symmetric && $t + $periods < $count)) {
|
||||
if ($count < $t || $count < $periods || ($symmetric && $t + $periods >= $count)) {
|
||||
throw new \Exception('Periods');
|
||||
}
|
||||
|
||||
$end = $symmetric ? $periods - 1 : 0;
|
||||
$end = $order % 2 === 0 ? $end - 1 : $end;
|
||||
$start = $t - 1 - ($periods - 2);
|
||||
$t += 2;
|
||||
$end = $symmetric ? $t + $periods - 1 : $t - 1;
|
||||
$start = $t - 1 - $periods;
|
||||
|
||||
if (!empty($weight)) {
|
||||
return self::weightedAverage(\array_slice($x, $start, $end - $start), \array_slice($weight, $start, $end - $start));
|
||||
|
|
|
|||
|
|
@ -37,6 +37,6 @@ class LevelLevelRegression extends RegressionAbstract
|
|||
*/
|
||||
public static function getElasticity(float $b1, float $y, float $x): float
|
||||
{
|
||||
return $b1 * $y / $x;
|
||||
return $b1 * $x / $y;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,6 @@ class LevelLogRegression extends RegressionAbstract
|
|||
*/
|
||||
public static function getElasticity(float $b1, float $y, float $x): float
|
||||
{
|
||||
return $b1 / $x;
|
||||
return $b1 / $y;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ final class Argument implements UriInterface
|
|||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $port = 80;
|
||||
private $port = 0;
|
||||
|
||||
/**
|
||||
* Uri user.
|
||||
|
|
@ -146,10 +146,89 @@ final class Argument implements UriInterface
|
|||
{
|
||||
$this->uri = $uri;
|
||||
|
||||
$temp = $this->__toString();
|
||||
$found = \stripos($temp, ':');
|
||||
$path = $found !== false && $found > 3 && $found < 8 ? \substr($temp, $found) : $temp;
|
||||
$this->path = $path === false ? '' : $path;
|
||||
$this->setPath($uri);
|
||||
$this->setQuery($uri);
|
||||
$this->setFragment($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path from uri.
|
||||
*
|
||||
* @param string $uri Uri to parse
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function setPath(string $uri) : void
|
||||
{
|
||||
$start = \stripos($uri, ':');
|
||||
|
||||
if ($start === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$end = \stripos($uri, ' ', $start + 1);
|
||||
|
||||
if ($end === false) {
|
||||
$end = \strlen($uri);
|
||||
}
|
||||
|
||||
$path = $start < 8 ? \substr($uri, $start + 1, $end - $start - 1) : $uri;
|
||||
$this->path = $path === false ? '' : \ltrim($path, ':');
|
||||
|
||||
if (StringUtils::endsWith($this->path, '.php')) {
|
||||
$path = \substr($this->path, 0, -4);
|
||||
|
||||
if ($path === false) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->path = $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set query from uri.
|
||||
*
|
||||
* @param string $uri Uri to parse
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function setQuery(string $uri) : void
|
||||
{
|
||||
$result = \preg_match_all('/\?([a-zA-Z0-9]*)(=)([a-zA-Z0-9]*)/', $uri, $matches);
|
||||
|
||||
if ($result === false || empty($matches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($matches[1] as $key => $value) {
|
||||
$this->query[$value] = $matches[3][$key];
|
||||
$this->queryString .= ' ?' . $value . '=' . $matches[3][$key];
|
||||
}
|
||||
|
||||
$this->queryString = \ltrim($this->queryString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fragment from uri.
|
||||
*
|
||||
* @param string $uri Uri to parse
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function setFragment(string $uri) : void
|
||||
{
|
||||
$result = \preg_match('/#([a-zA-Z0-9]*)/', $uri, $matches);
|
||||
|
||||
if ($result === 1) {
|
||||
$this->fragment = $matches[1] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -235,7 +314,7 @@ final class Argument implements UriInterface
|
|||
public function getRoute() : string
|
||||
{
|
||||
$query = $this->getQuery();
|
||||
return $this->path . (!empty($query) ? '?' . $this->getQuery() : '');
|
||||
return $this->path . (!empty($query) ? ' ' . $this->getQuery() : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
|
||||
namespace phpOMS\tests\DataStorage\Session;
|
||||
|
||||
use phpOMS\DataStorage\Session\ConsoleSession;
|
||||
|
||||
class ConsoleSessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder()
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
|
||||
namespace phpOMS\tests\DataStorage\Session;
|
||||
|
||||
use phpOMS\DataStorage\Session\SocketSession;
|
||||
|
||||
class SocketSessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder()
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
|
||||
namespace phpOMS\tests\DataStorage\Web;
|
||||
|
||||
use phpOMS\DataStorage\Web\Builder;
|
||||
|
||||
class BuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder()
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ use phpOMS\Math\Matrix\CholeskyDecomposition;
|
|||
|
||||
class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCombination()
|
||||
public function testComposition()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
|
|
@ -30,11 +30,13 @@ class CholeskyDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$cholesky = new CholeskyDecomposition($A);
|
||||
|
||||
self::assertEquals([
|
||||
[25, 15, -5],
|
||||
[15, 17, 0],
|
||||
[-5, 0, 11],
|
||||
], $cholesky->getL()->mult($cholesky->getL()->transpose())->toArray(), '', 0.2);
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$cholesky->getL()
|
||||
->mult($cholesky->getL()->transpose())
|
||||
->toArray(),
|
||||
'', 0.2
|
||||
);
|
||||
}
|
||||
|
||||
public function testDecomposition()
|
||||
|
|
|
|||
|
|
@ -44,12 +44,6 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
[0, 2, 0],
|
||||
[0, 0, 5],
|
||||
], $eig->getD()->toArray(), '', 0.2);
|
||||
|
||||
self::assertEquals([
|
||||
[3, 1, 1],
|
||||
[1, 2, 2],
|
||||
[1, 2, 2],
|
||||
], $eig->getV()->mult($eig->getD())->mult($eig->getV()->transpose())->toArray(), '', 0.2);
|
||||
}
|
||||
|
||||
public function testNonSymmetricMatrix()
|
||||
|
|
@ -77,11 +71,46 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
[0, 3, 0],
|
||||
[0, 0, 6],
|
||||
], $eig->getD()->toArray(), '', 0.2);
|
||||
}
|
||||
|
||||
self::assertEquals([
|
||||
public function testCompositeSymmetric()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
[3, 1, 1],
|
||||
[1, 2, 2],
|
||||
[1, 2, 2],
|
||||
]);
|
||||
|
||||
$eig = new EigenvalueDecomposition($A);
|
||||
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$eig->getV()
|
||||
->mult($eig->getD())
|
||||
->mult($eig->getV()->transpose())
|
||||
->toArray()
|
||||
, '', 0.2);
|
||||
}
|
||||
|
||||
public function testCompositeNonSymmetric()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
[-2, -4, 2],
|
||||
[-2, 1, 2],
|
||||
[4, 2, 5],
|
||||
], $eig->getV()->mult($eig->getD())->mult($eig->getV()->transpose())->toArray(), '', 0.2);
|
||||
]);
|
||||
|
||||
$eig = new EigenvalueDecomposition($A);
|
||||
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$eig->getV()
|
||||
->mult($eig->getD())
|
||||
->mult($eig->getV()->transpose())
|
||||
->toArray(),
|
||||
'', 0.2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -83,6 +83,26 @@ class LUDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
$lu->solve($vec);
|
||||
}
|
||||
|
||||
public function testComposition()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
[25, 15, -5],
|
||||
[15, 17, 0],
|
||||
[-5, 0, 11],
|
||||
]);
|
||||
|
||||
$lu = new LUDecomposition($A);
|
||||
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$lu->getL()
|
||||
->mult($lu->getU())
|
||||
->toArray(),
|
||||
'', 0.2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -364,18 +364,4 @@ class MatrixTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$A->sub($B);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimensionMult()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([[1, 2], [3, 4]]);
|
||||
|
||||
$B = new Matrix();
|
||||
$B->setMatrix([[1, 2, 1], [3, 4, 1], [5, 6, 1]]);
|
||||
|
||||
$A->mult($B);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,24 +33,36 @@ class QRDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue($QR->isFullRank());
|
||||
|
||||
self::assertEquals([
|
||||
[-6 / 7, 69 / 175, 58 / 175],
|
||||
[-6 / 7, 69 / 175, -58 / 175],
|
||||
[-3 / 7, -158 / 175, -6 / 175],
|
||||
[2 / 7, -6 / 35, 33 / 35],
|
||||
[2 / 7, -6 / 35, -33 / 35],
|
||||
], $QR->getQ()->toArray(), '', 0.2);
|
||||
|
||||
self::assertEquals([
|
||||
[-14, -21, 14],
|
||||
[0, -175, 70],
|
||||
[0, 0, -35],
|
||||
[0, 0, 35],
|
||||
], $QR->getR()->toArray(), '', 0.2);
|
||||
}
|
||||
|
||||
self::assertEquals($A->toArray(), $QR->getQ()->mult($QR->getR()), '', 0.2);
|
||||
public function testComposition()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
[12, -51, 4],
|
||||
[6, 167, -68],
|
||||
[-4, 24, -41],
|
||||
]);
|
||||
|
||||
self::assertEquals([
|
||||
[12, -69, -58 / 5],
|
||||
[6, 158, 6 / 5],
|
||||
[-4, 30, -33],
|
||||
], $QR->getH()->toArray(), '', 0.2);
|
||||
$QR = new QRDecomposition($A);
|
||||
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$QR->getQ()
|
||||
->mult($QR->getR())
|
||||
->toArray(),
|
||||
'', 0.2
|
||||
);
|
||||
}
|
||||
|
||||
public function testSolve()
|
||||
|
|
|
|||
|
|
@ -48,4 +48,24 @@ class SingularValueDecompositionTest extends \PHPUnit\Framework\TestCase
|
|||
[-0.6071, 0.1267, 0.7845],
|
||||
], $svd->getV()->toArray(), '', 0.2);
|
||||
}
|
||||
|
||||
public function testComposition()
|
||||
{
|
||||
$A = new Matrix();
|
||||
$A->setMatrix([
|
||||
[2, -2, 1],
|
||||
[5, 1, 4],
|
||||
]);
|
||||
|
||||
$svd = new SingularValueDecomposition($A);
|
||||
|
||||
self::assertEquals(
|
||||
$A->toArray(),
|
||||
$svd->getU()
|
||||
->mult($svd->getS())
|
||||
->mult($svd->getV()->transpose())
|
||||
->toArray(),
|
||||
'', 0.2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,18 +22,8 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(-3 / 2, Average::averageDatasetChange([6, 7, 6, 3, 0]));
|
||||
}
|
||||
|
||||
public function testMean()
|
||||
public function testAngleMean()
|
||||
{
|
||||
self::assertEquals(4, Average::arithmeticMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
|
||||
self::assertEquals(69 / 20, Average::weightedAverage(
|
||||
[1, 2, 3, 4, 5, 6, 7],
|
||||
[0.1, 0.2, 0.3, 0.1, 0.2, 0.05, 0.05]
|
||||
), '', 0.01);
|
||||
|
||||
self::assertEquals(3.3800151591413, Average::geometricMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
self::assertEquals(2.6997245179063, Average::harmonicMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
|
||||
self::assertEquals(-90, Average::angleMean([90.0, 180.0, 270.0, 360.0]), '', 0.01);
|
||||
self::assertEquals(9.999999999999977, Average::angleMean([370.0]), '', 0.01);
|
||||
|
||||
|
|
@ -41,6 +31,41 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(9.999999999999977, Average::angleMean2([370.0]), '', 0.01);
|
||||
}
|
||||
|
||||
public function testArithmeticMean()
|
||||
{
|
||||
self::assertEquals(4, Average::arithmeticMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
}
|
||||
|
||||
public function testWeightedAverage()
|
||||
{
|
||||
self::assertEquals(69 / 20, Average::weightedAverage(
|
||||
[1, 2, 3, 4, 5, 6, 7],
|
||||
[0.1, 0.2, 0.3, 0.1, 0.2, 0.05, 0.05]
|
||||
), '', 0.01);
|
||||
}
|
||||
|
||||
public function testGeometricMean()
|
||||
{
|
||||
self::assertEquals(3.3800151591413, Average::geometricMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
}
|
||||
|
||||
public function testHarmonicMean()
|
||||
{
|
||||
self::assertEquals(2.6997245179063, Average::harmonicMean([1, 2, 3, 4, 5, 6, 7]), '', 0.01);
|
||||
}
|
||||
|
||||
public function testMovingAverage()
|
||||
{
|
||||
$data = [
|
||||
67.5, 66.5, 66.44, 66.44, 66.25, 65.88, 66.63, 66.56, 65.63, 66.06,
|
||||
63.94, 64.13, 64.50, 62.81, 61.88, 62.50, 61.44, 60.13, 61.31, 61.38,
|
||||
];
|
||||
|
||||
$average = [66.39, 66.03, 65.79, 65.6, 65.24, 64.8, 64.46, 63.94, 63.3, 62.87, 62.4];
|
||||
|
||||
self::assertEquals($average, Average::totalMovingAverage($data, 10), '', 0.1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,16 +17,40 @@ use phpOMS\Math\Statistic\Forecast\Regression\LevelLevelRegression;
|
|||
|
||||
class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testRegression()
|
||||
protected $reg = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// y = 3 + 4 * x
|
||||
$x = [0, 1, 2, 3, 4];
|
||||
$y = [3, 7, 11, 15, 19];
|
||||
|
||||
$reg = LevelLevelRegression::getRegression($x, $y);
|
||||
$this->reg = LevelLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
self::assertEquals(['b0' => 3, 'b1' => 4], $reg, '', 0.2);
|
||||
self::assertEquals(4, LevelLevelRegression::getSlope($reg['b1'], 0, 0));
|
||||
self::assertEquals(22, LevelLevelRegression::getElasticity($reg['b1'], 11, 2));
|
||||
public function testRegression()
|
||||
{
|
||||
self::assertEquals(['b0' => 3, 'b1' => 4], $this->reg, '', 0.2);
|
||||
}
|
||||
|
||||
public function testSlope()
|
||||
{
|
||||
self::assertEquals(4, LevelLevelRegression::getSlope($this->reg['b1'], 0, 0));
|
||||
}
|
||||
|
||||
public function testElasticity()
|
||||
{
|
||||
self::assertEquals(0.7273, LevelLevelRegression::getElasticity($this->reg['b1'], 11, 2), '', 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension()
|
||||
{
|
||||
$x = [1,2, 3];
|
||||
$y = [1,2, 3, 4];
|
||||
|
||||
LevelLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,18 +14,45 @@
|
|||
namespace phpOMS\tests\Math\Statistic\Forecast\Regression;
|
||||
|
||||
use phpOMS\Math\Statistic\Forecast\Regression\LevelLogRegression;
|
||||
use phpOMS\Math\Statistic\Forecast\Regression\LevelLevelRegression;
|
||||
|
||||
class LevelLogRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testRegression()
|
||||
protected $reg = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// y = 1 + log(x)
|
||||
$x = [0.25, 0.5, 1, 1.5];
|
||||
$y = [-0.386, 0.307, 1, 1.405];
|
||||
|
||||
$reg = LevelLogRegression::getRegression($x, $y);
|
||||
$this->reg = LevelLogRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
self::assertEquals(['b0' => 1, 'b1' => 1], $reg, '', 0.2);
|
||||
public function testRegression()
|
||||
{
|
||||
self::assertEquals(['b0' => 1, 'b1' => 1], $this->reg, '', 0.2);
|
||||
}
|
||||
|
||||
public function testSlope()
|
||||
{
|
||||
$x = 2;
|
||||
self::assertEquals($this->reg['b1'] / $x, LevelLogRegression::getSlope($this->reg['b1'], 0, $x), '', 0.2);
|
||||
}
|
||||
|
||||
public function testElasticity()
|
||||
{
|
||||
$y = 3;
|
||||
self::assertEquals($this->reg['b1'] / $y, LevelLogRegression::getElasticity($this->reg['b1'], $y, 0), '', 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension()
|
||||
{
|
||||
$x = [1,2, 3];
|
||||
$y = [1,2, 3, 4];
|
||||
|
||||
LevelLogRegression::getRegression($x, $y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,42 @@ use phpOMS\Math\Statistic\Forecast\Regression\LogLevelRegression;
|
|||
|
||||
class LogLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testRegression()
|
||||
protected $reg = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// ln(y) = -1 + 2 * x => y = e^(-1 + 2 * x)
|
||||
$x = [0.25, 0.5, 1, 1.5];
|
||||
$y = [0.6065, 1, 2.718, 7.389];
|
||||
|
||||
$reg = LogLevelRegression::getRegression($x, $y);
|
||||
$this->reg = LogLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
self::assertEquals(['b0' => -1, 'b1' => 2], $reg, '', 0.2);
|
||||
public function testRegression()
|
||||
{
|
||||
self::assertEquals(['b0' => -1, 'b1' => 2], $this->reg, '', 0.2);
|
||||
}
|
||||
|
||||
public function testSlope()
|
||||
{
|
||||
$y = 3;
|
||||
self::assertEquals($this->reg['b1'] * $y, LogLevelRegression::getSlope($this->reg['b1'], $y, 0), '', 0.2);
|
||||
}
|
||||
|
||||
public function testElasticity()
|
||||
{
|
||||
$x = 2;
|
||||
self::assertEquals($this->reg['b1'] * $x, LogLevelRegression::getElasticity($this->reg['b1'], 0, $x), '', 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension()
|
||||
{
|
||||
$x = [1,2, 3];
|
||||
$y = [1,2, 3, 4];
|
||||
|
||||
LogLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,42 @@ use phpOMS\Math\Statistic\Forecast\Regression\LogLogRegression;
|
|||
|
||||
class LogLogRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testRegression()
|
||||
protected $reg = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
// ln(y) = 2 + 3 * ln(x) => y = e^(2 + 3 * ln(x))
|
||||
$x = [0.25, 0.5, 1, 1.5];
|
||||
$y = [0.115, 0.924, 7.389, 24.938];
|
||||
|
||||
$reg = LogLogRegression::getRegression($x, $y);
|
||||
$this->reg = LogLogRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
self::assertEquals(['b0' => 2, 'b1' => 3], $reg, '', 0.2);
|
||||
public function testRegression()
|
||||
{
|
||||
self::assertEquals(['b0' => 2, 'b1' => 3], $this->reg, '', 0.2);
|
||||
}
|
||||
|
||||
public function testSlope()
|
||||
{
|
||||
$y = 3;
|
||||
$x = 2;
|
||||
self::assertEquals($this->reg['b1'] * $y / $x, LogLogRegression::getSlope($this->reg['b1'], $y, $x), '', 0.2);
|
||||
}
|
||||
|
||||
public function testElasticity()
|
||||
{
|
||||
self::assertEquals($this->reg['b1'], LogLogRegression::getElasticity($this->reg['b1'], 0, 0), '', 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \phpOMS\Math\Matrix\Exception\InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension()
|
||||
{
|
||||
$x = [1,2, 3];
|
||||
$y = [1,2, 3, 4];
|
||||
|
||||
LogLogRegression::getRegression($x, $y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
76
tests/Uri/ArgumentTest.php
Normal file
76
tests/Uri/ArgumentTest.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
|
||||
namespace phpOMS\tests\Uri;
|
||||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
use phpOMS\Uri\Argument;
|
||||
|
||||
class ArgumentTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testAttributes()
|
||||
{
|
||||
$obj = new Argument('');
|
||||
|
||||
/* Testing members */
|
||||
self::assertObjectHasAttribute('rootPath', $obj);
|
||||
self::assertObjectHasAttribute('uri', $obj);
|
||||
self::assertObjectHasAttribute('scheme', $obj);
|
||||
self::assertObjectHasAttribute('host', $obj);
|
||||
self::assertObjectHasAttribute('port', $obj);
|
||||
self::assertObjectHasAttribute('user', $obj);
|
||||
self::assertObjectHasAttribute('pass', $obj);
|
||||
self::assertObjectHasAttribute('path', $obj);
|
||||
self::assertObjectHasAttribute('query', $obj);
|
||||
self::assertObjectHasAttribute('queryString', $obj);
|
||||
self::assertObjectHasAttribute('fragment', $obj);
|
||||
self::assertObjectHasAttribute('base', $obj);
|
||||
}
|
||||
|
||||
public function testHelper()
|
||||
{
|
||||
self::assertTrue(Argument::isValid('http://www.google.de'));
|
||||
self::assertTrue(Argument::isValid('http://google.de'));
|
||||
self::assertTrue(Argument::isValid('https://google.de'));
|
||||
self::assertTrue(Argument::isValid('skladf klsdee; eleklt ,- -sdf er'));
|
||||
self::assertTrue(Argument::isValid('https:/google.de'));
|
||||
}
|
||||
|
||||
public function testSetGet()
|
||||
{
|
||||
$obj = new Argument($uri = ':modules/admin/test/path.php ?para1=abc ?para2=2 #frag');
|
||||
|
||||
self::assertEquals('/', $obj->getRootPath());
|
||||
self::assertEquals(0, $obj->getPathOffset());
|
||||
self::assertEquals('', $obj->getScheme());
|
||||
self::assertEquals('', $obj->getHost());
|
||||
self::assertEquals(0, $obj->getPort());
|
||||
self::assertEquals('', $obj->getPass());
|
||||
self::assertEquals('', $obj->getUser());
|
||||
self::assertEquals('modules/admin/test/path', $obj->getPath());
|
||||
self::assertEquals('modules/admin/test/path ?para1=abc ?para2=2', $obj->getRoute());
|
||||
self::assertEquals('modules', $obj->getPathElement(0));
|
||||
self::assertEquals('?para1=abc ?para2=2', $obj->getQuery());
|
||||
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
|
||||
self::assertEquals('2', $obj->getQuery('para2'));
|
||||
self::assertEquals('frag', $obj->getFragment());
|
||||
self::assertEquals('', $obj->getBase());
|
||||
self::assertEquals($uri, $obj->__toString());
|
||||
self::assertEquals('', $obj->getAuthority());
|
||||
self::assertEquals('', $obj->getUserInfo());
|
||||
|
||||
$obj->setRootPath('a');
|
||||
self::assertEquals('a', $obj->getRootPath());
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ class HttpTest extends \PHPUnit\Framework\TestCase
|
|||
public function testAttributes()
|
||||
{
|
||||
$obj = new Http('');
|
||||
self::assertInstanceOf('\phpOMS\Uri\Http', $obj);
|
||||
|
||||
/* Testing members */
|
||||
self::assertObjectHasAttribute('rootPath', $obj);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user