fix tests

This commit is contained in:
Dennis Eichhorn 2023-10-22 19:00:42 +00:00
parent 4bed0db195
commit 630a38b897
4 changed files with 70 additions and 25 deletions

View File

@ -162,18 +162,6 @@ class Matrix implements \ArrayAccess, \Iterator
return $matrix;
}
/**
* Get matrix array.
*
* @return array<int, array<int, mixed>>
*
* @since 1.0.0
*/
public function getMatrix() : array
{
return $this->matrix;
}
/**
* Get sub matrix array.
*
@ -451,7 +439,7 @@ class Matrix implements \ArrayAccess, \Iterator
throw new InvalidDimensionException($matrix->getM() . 'x' . $matrix->getN());
}
$matrixArr = $matrix->getMatrix();
$matrixArr = $matrix->toArray();
$newMatrixArr = $this->matrix;
foreach ($newMatrixArr as $i => $vector) {
@ -553,9 +541,9 @@ class Matrix implements \ArrayAccess, \Iterator
throw new InvalidDimensionException($mDim . 'x' . $nDim);
}
$matrixArr = $matrix->getMatrix();
$matrixArr = $matrix->toArray();
$newMatrix = new self($this->m, $nDim);
$newMatrixArr = $newMatrix->getMatrix();
$newMatrixArr = $newMatrix->toArray();
for ($i = 0; $i < $this->m; ++$i) { // Row of $this
for ($c = 0; $c < $nDim; ++$c) { // Column of $matrix
@ -723,7 +711,7 @@ class Matrix implements \ArrayAccess, \Iterator
public function dot(self $B) : self
{
$value1 = $this->matrix;
$value2 = $B->getMatrix();
$value2 = $B->toArray();
$m1 = \count($value1);
$n1 = ($isMatrix1 = \is_array($value1[0])) ? \count($value1[0]) : 1;

View File

@ -47,7 +47,7 @@ final class MultipleLinearRegression extends RegressionAbstract
$Y = new Matrix(\count($y));
$Y->setMatrix($y);
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix();
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray();
}
/**

View File

@ -69,7 +69,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
*/
public function testMultMatrix() : void
{
self::assertEquals([[0, -5], [-6, -7]], $this->C->getMatrix());
self::assertEquals([[0, -5], [-6, -7]], $this->C->toArray());
}
/**
@ -79,7 +79,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
*/
public function testMultMatrixScalar() : void
{
self::assertEquals([[0, -10], [-12, -14]], $this->C->mult(2)->getMatrix());
self::assertEquals([[0, -10], [-12, -14]], $this->C->mult(2)->toArray());
}
/**
@ -291,7 +291,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
*/
public function testUpperTriangular() : void
{
self::assertEquals([[-6, -7], [0, -5]], $this->C->upperTriangular()->getMatrix());
self::assertEquals([[-6, -7], [0, -5]], $this->C->upperTriangular()->toArray());
}
/**
@ -301,8 +301,8 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
public function testLowerTriangular() : void
{
self::markTestIncomplete();
//self::assertEquals([], $this->C->lowerTriangular()->getMatrix());
//self::assertEquals([], $this->C->diagonalize()->getMatrix());
//self::assertEquals([], $this->C->lowerTriangular()->toArray());
//self::assertEquals([], $this->C->diagonalize()->toArray());
}
/**
@ -536,7 +536,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
[1, 5, 7],
[2, 6, 8],
])
)->toArray()
)->toVectorArray()
);
}
@ -552,7 +552,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase
[11, 39, 53],
$m->dot(
Vector::fromArray([3, 4])
)->toArray()
)->toVectorArray()
);
}

View File

@ -285,21 +285,27 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
*/
private function dbSetup() : void
{
\phpOMS\Log\FileLogger::getInstance()->verbose = true;
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_base` (
`test_base_id` int(11) NOT NULL AUTO_INCREMENT,
`test_base_string` varchar(254) NOT NULL,
`test_base_compress` BLOB NOT NULL,
`test_base_pstring` varchar(254) NOT NULL,
`test_base_int` int(11) NOT NULL,
`test_base_bool` tinyint(1) DEFAULT NULL,
`test_base_null` int(11) DEFAULT NULL,
`test_base_float` decimal(5, 4) DEFAULT NULL,
`test_base_belongs_to_one` int(11) DEFAULT NULL,
`test_base_belongs_top_one` int(11) DEFAULT NULL,
`test_base_owns_one_self` int(11) DEFAULT NULL,
`test_base_owns_onep_self` int(11) DEFAULT NULL,
`test_base_json` varchar(254) DEFAULT NULL,
`test_base_json_serializable` varchar(254) DEFAULT NULL,
`test_base_serializable` varchar(254) DEFAULT NULL,
`test_base_datetime` datetime DEFAULT NULL,
`test_base_datetime_null` datetime DEFAULT NULL, /* There was a bug where it returned the current date because new \DateTime(null) === current date which is wrong, we want null as value! */
`test_base_datetime_null` datetime DEFAULT NULL,
PRIMARY KEY (`test_base_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
@ -355,6 +361,49 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
PRIMARY KEY (`test_has_many_rel_relations_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
// private
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_has_many_directp` (
`test_has_many_directp_id` int(11) NOT NULL AUTO_INCREMENT,
`test_has_many_directp_string` varchar(254) NOT NULL,
`test_has_many_directp_to` int(11) NOT NULL,
PRIMARY KEY (`test_has_many_directp_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_has_many_relp` (
`test_has_many_relp_id` int(11) NOT NULL AUTO_INCREMENT,
`test_has_many_relp_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_has_many_relp_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_has_many_rel_relationsp` (
`test_has_many_rel_relationsp_id` int(11) NOT NULL AUTO_INCREMENT,
`test_has_many_rel_relationsp_src` int(11) NOT NULL,
`test_has_many_rel_relationsp_dest` int(11) NOT NULL,
PRIMARY KEY (`test_has_many_rel_relationsp_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_belongs_to_onep` (
`test_belongs_to_onep_id` int(11) NOT NULL AUTO_INCREMENT,
`test_belongs_to_onep_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_belongs_to_onep_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
$GLOBALS['dbpool']->get()->con->prepare(
'CREATE TABLE `test_owns_onep` (
`test_owns_onep_id` int(11) NOT NULL AUTO_INCREMENT,
`test_owns_onep_string` varchar(254) NOT NULL,
PRIMARY KEY (`test_owns_onep_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'
)->execute();
}
/**
@ -369,6 +418,14 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_directp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_relp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relationsp')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_onep')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_onep')->execute();
\phpOMS\Log\FileLogger::getInstance()->verbose = false;
}
/**