diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 14d48fbc9..7af90b442 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -297,6 +297,25 @@ class Matrix implements \ArrayAccess, \Iterator return $this->matrix; } + /** + * Get matrix as 1D array. + * + * @return array + * + * @since 1.0.0 + */ + public function toVectorArray() : array + { + $result = []; + for ($i = 0; $i < $this->m; ++$i) { + for ($j = 0; $j < $this->n; ++$j) { + $result[] = $this->matrix[$i][$j]; + } + } + + return $result; + } + /** * Is symmetric. * diff --git a/tests/Math/Matrix/VectorTest.php b/tests/Math/Matrix/VectorTest.php index 4e31ab7f1..70200aa89 100755 --- a/tests/Math/Matrix/VectorTest.php +++ b/tests/Math/Matrix/VectorTest.php @@ -78,7 +78,7 @@ final class VectorTest extends \PHPUnit\Framework\TestCase { self::assertEquals( [-15, -2, 39], - Vector::fromArray([3, -3, 1])->cross3(Vector::fromArray([4, 9, 2]))->toArray() + Vector::fromArray([3, -3, 1])->cross3(Vector::fromArray([4, 9, 2]))->toVectorArray() ); } } diff --git a/tests/Message/RequestAbstractTest.php b/tests/Message/RequestAbstractTest.php index c317be50d..719d4f448 100755 --- a/tests/Message/RequestAbstractTest.php +++ b/tests/Message/RequestAbstractTest.php @@ -149,8 +149,8 @@ final class RequestAbstractTest extends \PHPUnit\Framework\TestCase public function testDataDateTimeInputOutput() : void { $this->request->setData('asdf', '2023-01-01'); - self::assertEquals((new \DateTime('2023-01-01'))->format('Y-m-d'), $this->request->getDataDateTime('asdf')); - self::assertEquals((new \DateTime('2023-01-01'))->format('Y-m-d'), $this->request->getData('asdf', 'float')); + self::assertEquals((new \DateTime('2023-01-01'))->format('Y-m-d'), $this->request->getDataDateTime('asdf')->format('Y-m-d')); + self::assertEquals((new \DateTime('2023-01-01'))->format('Y-m-d'), $this->request->getData('asdf', 'DateTime')->format('Y-m-d')); } public function testDataInvalidTypeInputOutput() : void diff --git a/tests/Message/ResponseAbstractTest.php b/tests/Message/ResponseAbstractTest.php index 52c1fdc92..dd1edf283 100755 --- a/tests/Message/ResponseAbstractTest.php +++ b/tests/Message/ResponseAbstractTest.php @@ -70,7 +70,7 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase public function testDataAllInputOutput() : void { $this->response->set('asdf', false); - self::assertFalse(['asdf' => false], $this->response->getData()); + self::assertEquals(['asdf' => false], $this->response->getData()); } /** @@ -127,7 +127,6 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase { $this->response->set('asdf', '[1,2,3]'); self::assertEquals([1,2,3], $this->response->getDataJson('asdf')); - self::assertEquals([1,2,3], $this->response->getData('asdf', 'json')); } /**