From 95eb37853e711c358ed9c50667d1419707c0baa5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 22 Oct 2023 20:55:05 +0000 Subject: [PATCH] fix tests --- Math/Matrix/Matrix.php | 6 ++++-- Utils/ImageUtils.php | 2 +- tests/Math/Matrix/MatrixTest.php | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 465f12a3f..f8d5f6d10 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -714,10 +714,10 @@ class Matrix implements \ArrayAccess, \Iterator $value2 = $B->toArray(); $m1 = \count($value1); - $n1 = ($isMatrix1 = \is_array($value1[0])) ? \count($value1[0]) : 1; + $n1 = ($isMatrix1 = !($this instanceof Vector)) ? \count($value1[0]) : 1; $m2 = \count($value2); - $n2 = ($isMatrix2 = \is_array($value2[0])) ? \count($value2[0]) : 1; + $n2 = ($isMatrix2 = !($B instanceof Vector)) ? \count($value2[0]) : 1; $result = null; @@ -908,6 +908,8 @@ class Matrix implements \ArrayAccess, \Iterator /** * Calculate e^M * + * The algorithm uses a taylor series. + * * @param int $iterations Iterations for approximation * * @return self diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index 72d596ad2..0f7ca4575 100755 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -315,7 +315,7 @@ final class ImageUtils //$color1 = \imagecolorat($src1, $i, $j); $color2 = \imagecolorat($src2, $i, $j); - if (\abs($color1Avg - $color2Avg) / $color1Avg > 0.05 && $color1Avg > 0 && $color2Avg > 0) { + if ($color1Avg > 0 && \abs($color1Avg - $color2Avg) / $color1Avg > 0.05 && $color2Avg > 0) { ++$difference; if ($diff === 0) { diff --git a/tests/Math/Matrix/MatrixTest.php b/tests/Math/Matrix/MatrixTest.php index f6a0d66fa..595330ab1 100755 --- a/tests/Math/Matrix/MatrixTest.php +++ b/tests/Math/Matrix/MatrixTest.php @@ -498,8 +498,8 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase $v1 = Vector::fromArray([1, 3, -5])->transpose(); self::assertEquals( - 3, - $v1->dot(Vector::fromArray([4, -2, -1])) + [[3]], + $v1->dot(Vector::fromArray([4, -2, -1]))->toArray() ); } @@ -580,7 +580,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase self::assertEquals( [12, 15, 18], - $m->sum(0) + $m->sum(0)->toVectorArray() ); } @@ -594,7 +594,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase self::assertEquals( [6, 15, 24], - $m->sum(1) + $m->sum(1)->toVectorArray() ); } @@ -614,7 +614,7 @@ final class MatrixTest extends \PHPUnit\Framework\TestCase [0, 0, -8], ]); - self::assertFalse($m->isDiagonal()); + self::assertTrue($m->isDiagonal()); } public function testPow() : void