diff --git a/DataStorage/Session/ConsoleSession.php b/DataStorage/Session/ConsoleSession.php
deleted file mode 100644
index 3dcddf636..000000000
--- a/DataStorage/Session/ConsoleSession.php
+++ /dev/null
@@ -1,102 +0,0 @@
-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
- {
- }
-}
diff --git a/DataStorage/Session/SocketSession.php b/DataStorage/Session/SocketSession.php
deleted file mode 100644
index cd1cec7b5..000000000
--- a/DataStorage/Session/SocketSession.php
+++ /dev/null
@@ -1,102 +0,0 @@
-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
- {
- }
-}
diff --git a/DataStorage/Web/Builder.php b/DataStorage/Web/Builder.php
deleted file mode 100644
index 7ad62bff4..000000000
--- a/DataStorage/Web/Builder.php
+++ /dev/null
@@ -1,103 +0,0 @@
-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
(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()];
- }
-}
diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php
index 98c6d1b8b..22e003d7d 100644
--- a/Math/Matrix/LUDecomposition.php
+++ b/Math/Matrix/LUDecomposition.php
@@ -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;
}
diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php
index c730ae298..7246d8eb5 100644
--- a/Math/Matrix/Matrix.php
+++ b/Math/Matrix/Matrix.php
@@ -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;
diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php
index 63f43c7ac..979f1e681 100644
--- a/Math/Statistic/Average.php
+++ b/Math/Statistic/Average.php
@@ -69,7 +69,7 @@ final class Average
}
/**
- * Moving average of dataset
+ * Moving average of dataset (SMA)
*
* @param array $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 $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));
diff --git a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php
index 1f3c54eec..011528058 100644
--- a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php
+++ b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php
@@ -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;
}
}
diff --git a/Math/Statistic/Forecast/Regression/LevelLogRegression.php b/Math/Statistic/Forecast/Regression/LevelLogRegression.php
index 498e53d9d..0ca1ea271 100644
--- a/Math/Statistic/Forecast/Regression/LevelLogRegression.php
+++ b/Math/Statistic/Forecast/Regression/LevelLogRegression.php
@@ -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;
}
}
diff --git a/Uri/Argument.php b/Uri/Argument.php
index 68b7861d9..4a0915162 100644
--- a/Uri/Argument.php
+++ b/Uri/Argument.php
@@ -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() : '');
}
/**
diff --git a/tests/DataStorage/Session/ConsoleSessionTest.php b/tests/DataStorage/Session/ConsoleSessionTest.php
deleted file mode 100644
index 1ce9f51ca..000000000
--- a/tests/DataStorage/Session/ConsoleSessionTest.php
+++ /dev/null
@@ -1,24 +0,0 @@
-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()
diff --git a/tests/Math/Matrix/EigenvalueDecompositionTest.php b/tests/Math/Matrix/EigenvalueDecompositionTest.php
index cbcb25924..47182b343 100644
--- a/tests/Math/Matrix/EigenvalueDecompositionTest.php
+++ b/tests/Math/Matrix/EigenvalueDecompositionTest.php
@@ -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
+ );
}
}
\ No newline at end of file
diff --git a/tests/Math/Matrix/LUDecompositionTest.php b/tests/Math/Matrix/LUDecompositionTest.php
index 4b1b06087..55e2ba850 100644
--- a/tests/Math/Matrix/LUDecompositionTest.php
+++ b/tests/Math/Matrix/LUDecompositionTest.php
@@ -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
*/
diff --git a/tests/Math/Matrix/MatrixTest.php b/tests/Math/Matrix/MatrixTest.php
index 5345dfb66..798b48351 100644
--- a/tests/Math/Matrix/MatrixTest.php
+++ b/tests/Math/Matrix/MatrixTest.php
@@ -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);
- }
}
diff --git a/tests/Math/Matrix/QRDecompositionTest.php b/tests/Math/Matrix/QRDecompositionTest.php
index 46af3ef79..a28c087a7 100644
--- a/tests/Math/Matrix/QRDecompositionTest.php
+++ b/tests/Math/Matrix/QRDecompositionTest.php
@@ -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()
diff --git a/tests/Math/Matrix/SingularValueDecompositionTest.php b/tests/Math/Matrix/SingularValueDecompositionTest.php
index df0c555bd..2d8fe17ab 100644
--- a/tests/Math/Matrix/SingularValueDecompositionTest.php
+++ b/tests/Math/Matrix/SingularValueDecompositionTest.php
@@ -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
+ );
+ }
}
diff --git a/tests/Math/Statistic/AverageTest.php b/tests/Math/Statistic/AverageTest.php
index 2b6147065..dba7cbbb3 100644
--- a/tests/Math/Statistic/AverageTest.php
+++ b/tests/Math/Statistic/AverageTest.php
@@ -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
*/
diff --git a/tests/Math/Statistic/Forecast/Regression/LevelLevelRegressionTest.php b/tests/Math/Statistic/Forecast/Regression/LevelLevelRegressionTest.php
index 30800a5ee..a97a3f36c 100644
--- a/tests/Math/Statistic/Forecast/Regression/LevelLevelRegressionTest.php
+++ b/tests/Math/Statistic/Forecast/Regression/LevelLevelRegressionTest.php
@@ -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);
}
}
diff --git a/tests/Math/Statistic/Forecast/Regression/LevelLogRegressionTest.php b/tests/Math/Statistic/Forecast/Regression/LevelLogRegressionTest.php
index 5691c2cae..38dbe8e18 100644
--- a/tests/Math/Statistic/Forecast/Regression/LevelLogRegressionTest.php
+++ b/tests/Math/Statistic/Forecast/Regression/LevelLogRegressionTest.php
@@ -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);
}
}
diff --git a/tests/Math/Statistic/Forecast/Regression/LogLevelRegressionTest.php b/tests/Math/Statistic/Forecast/Regression/LogLevelRegressionTest.php
index cfbf4ad9f..89f11dabf 100644
--- a/tests/Math/Statistic/Forecast/Regression/LogLevelRegressionTest.php
+++ b/tests/Math/Statistic/Forecast/Regression/LogLevelRegressionTest.php
@@ -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);
}
}
diff --git a/tests/Math/Statistic/Forecast/Regression/LogLogRegressionTest.php b/tests/Math/Statistic/Forecast/Regression/LogLogRegressionTest.php
index 96a4b2a50..6b9f7329a 100644
--- a/tests/Math/Statistic/Forecast/Regression/LogLogRegressionTest.php
+++ b/tests/Math/Statistic/Forecast/Regression/LogLogRegressionTest.php
@@ -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);
}
}
diff --git a/tests/Uri/ArgumentTest.php b/tests/Uri/ArgumentTest.php
new file mode 100644
index 000000000..18dd5f371
--- /dev/null
+++ b/tests/Uri/ArgumentTest.php
@@ -0,0 +1,76 @@
+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());
+ }
+}
\ No newline at end of file
diff --git a/tests/Uri/HttpTest.php b/tests/Uri/HttpTest.php
index 4e4b45bd0..c49aebb4b 100644
--- a/tests/Uri/HttpTest.php
+++ b/tests/Uri/HttpTest.php
@@ -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);
|