From 880c4efb0d7669b0263c9f2e4f60c96040d43d65 Mon Sep 17 00:00:00 2001 From: Andrew DalPino Date: Wed, 20 Sep 2023 15:51:28 -0500 Subject: [PATCH] Allow small numerical variance in unit tests --- benchmarks/Decompositions/CholeskyBench.php | 1 + phpbench.json.dist | 10 +- tests/ColumnVectorTest.php | 15 ++- tests/MatrixTest.php | 103 ++++++++++---------- tests/VectorTest.php | 82 +++++++++------- 5 files changed, 115 insertions(+), 96 deletions(-) diff --git a/benchmarks/Decompositions/CholeskyBench.php b/benchmarks/Decompositions/CholeskyBench.php index 7824a7f..60feee1 100644 --- a/benchmarks/Decompositions/CholeskyBench.php +++ b/benchmarks/Decompositions/CholeskyBench.php @@ -21,6 +21,7 @@ public function setUp() : void } /** + * @Skip * @Subject * @Iterations(5) * @OutputTimeUnit("seconds", precision=3) diff --git a/phpbench.json.dist b/phpbench.json.dist index f786950..d643897 100644 --- a/phpbench.json.dist +++ b/phpbench.json.dist @@ -1,9 +1,9 @@ { - "bootstrap": "vendor/autoload.php", - "path": "benchmarks", - "time_unit": "seconds", - "progress": "blinken", - "php_config": { + "runner.bootstrap": "vendor/autoload.php", + "runner.path": "benchmarks", + "runner.time_unit": "seconds", + "runner.progress": "blinken", + "runner.php_config": { "memory_limit": "-1" } } \ No newline at end of file diff --git a/tests/ColumnVectorTest.php b/tests/ColumnVectorTest.php index 659fd45..48ad4c7 100644 --- a/tests/ColumnVectorTest.php +++ b/tests/ColumnVectorTest.php @@ -19,6 +19,13 @@ */ class ColumnVectorTest extends TestCase { + /** + * The maximum error tolerated due to varying numerical precision. + * + * @var float + */ + protected const MAX_DELTA = 1e-8; + /** * @test */ @@ -108,7 +115,7 @@ public function multiply() : void [38.5, 175, -175], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -132,7 +139,7 @@ public function divide() : void [31.818181818181817, 7, -7], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -156,7 +163,7 @@ public function add() : void [36.1, 40, 30], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -180,7 +187,7 @@ public function subtract() : void [33.9, 30, 40], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** diff --git a/tests/MatrixTest.php b/tests/MatrixTest.php index 8683ef7..be55dd8 100644 --- a/tests/MatrixTest.php +++ b/tests/MatrixTest.php @@ -27,6 +27,13 @@ */ class MatrixTest extends TestCase { + /** + * The maximum error tolerated due to varying numerical precision. + * + * @var float + */ + protected const MAX_DELTA = 1e-8; + /** * @test */ @@ -369,9 +376,7 @@ public function asVectors() : void Vector::quick([20, -6, -9]), ]; - foreach ($vectors as $i => $vector) { - $this->assertEquals($expected[$i], $vector); - } + $this->assertEquals($expected, $vectors); } /** @@ -393,9 +398,7 @@ public function asColumnVectors() : void ColumnVector::quick([12, -2, -9]), ]; - foreach ($vectors as $i => $vector) { - $this->assertEquals($expected[$i], $vector); - } + $this->assertEquals($expected, $vectors); } /** @@ -457,7 +460,7 @@ public function inverse() : void [0.04602036967182196, 0.03923047906450396, -0.05846850245190495], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -479,7 +482,7 @@ public function pseudoinverse() : void [0.01266554551187723, -0.0031357298016957483], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -493,7 +496,7 @@ public function det() : void [-10, -1, 14], ]); - $this->assertEquals(-544.0, $a->det()); + $this->assertEqualsWithDelta(-544.0, $a->det(), self::MAX_DELTA); } /** @@ -593,7 +596,7 @@ public function reciprocal() : void [0.05, -0.16666666666666666, -0.1111111111111111], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -643,7 +646,7 @@ public function ref() : void $expected = new REF($a, 0); - $this->assertEqualsWithDelta($expected, $ref, 1e-8); + $this->assertEqualsWithDelta($expected, $ref, self::MAX_DELTA); } /** @@ -667,7 +670,7 @@ public function rref() : void $expected = new RREF($a); - $this->assertEqualsWithDelta($expected, $rref, 1e-8); + $this->assertEqualsWithDelta($expected, $rref, self::MAX_DELTA); } /** @@ -703,7 +706,7 @@ public function lu() : void $expected = new LU($l, $u, $p); - $this->assertEqualsWithDelta($expected, $lu, 1e-8); + $this->assertEqualsWithDelta($expected, $lu, self::MAX_DELTA); } /** @@ -727,7 +730,7 @@ public function cholesky() : void $expected = new Cholesky($l); - $this->assertEquals($expected, $cholesky); + $this->assertEqualsWithDelta($expected, $cholesky, self::MAX_DELTA); } /** @@ -742,7 +745,7 @@ public function eig(Matrix $matrix, Eigen $expected) : void { $eig = $matrix->eig(false); - $this->assertEqualsWithDelta($expected, $eig, 1e-8); + $this->assertEqualsWithDelta($expected, $eig, self::MAX_DELTA); } /** @@ -793,7 +796,7 @@ public function eigSymmetric() : void $expected = new Eigen($values, $vectors); - $this->assertEqualsWithDelta($expected, $eig, 1e-8); + $this->assertEqualsWithDelta($expected, $eig, self::MAX_DELTA); } /** @@ -828,7 +831,7 @@ public function svd() : void $expected = new SVD($u, $singularValues, $vT); - $this->assertEqualsWithDelta($expected, $svd, 1e-8); + $this->assertEqualsWithDelta($expected, $svd, self::MAX_DELTA); } /** @@ -854,7 +857,7 @@ public function matmul() : void [207], [155], [113], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -874,7 +877,7 @@ public function dotVector() : void $expected = ColumnVector::quick([-138, 120, -11]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -908,7 +911,7 @@ public function convolve() : void [0, 3, 19, 26, 27, 33], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -923,7 +926,7 @@ public function multiply(Matrix $a, $b, $expected) : void { $c = $a->multiply($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -1004,7 +1007,7 @@ public function divide(Matrix $a, $b, $expected) : void { $c = $a->divide($b); - $this->assertEqualsWithDelta($expected, $c, 1e-8); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -1085,7 +1088,7 @@ public function add(Matrix $a, $b, $expected) : void { $c = $a->add($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -1166,7 +1169,7 @@ public function subtract(Matrix $a, $b, $expected) : void { $c = $a->subtract($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -1247,7 +1250,7 @@ public function pow(Matrix $a, $b, $expected) : void { $c = $a->pow($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -1910,7 +1913,7 @@ public function square() : void [400, 36, 81], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1932,7 +1935,7 @@ public function sqrt() : void [3], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1954,7 +1957,7 @@ public function exp() : void [8103.08392757538], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1976,7 +1979,7 @@ public function expm1() : void [8102.083927575384], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1998,7 +2001,7 @@ public function log() : void [2.1972245773362196], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2020,7 +2023,7 @@ public function log1p() : void [2.302585092994046], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2042,7 +2045,7 @@ public function sin() : void [0.4121184852417566], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2064,7 +2067,7 @@ public function asin() : void [0.010000166674167114], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2086,7 +2089,7 @@ public function cos() : void [-0.9111302618846769], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2108,7 +2111,7 @@ public function acos() : void [1.5607961601207294], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2130,7 +2133,7 @@ public function tan() : void [-0.45231565944180985], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2152,7 +2155,7 @@ public function atan() : void [1.460139105621001], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2174,7 +2177,7 @@ public function rad2deg() : void [515.6620156177408], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2196,7 +2199,7 @@ public function deg2rad() : void [0.15707963267948966], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2214,7 +2217,7 @@ public function sum() : void $expected = ColumnVector::quick([17, 13, 5]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2232,7 +2235,7 @@ public function product() : void $expected = ColumnVector::quick([-4488.0, -88.0, 1080.0]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2286,7 +2289,7 @@ public function mean() : void $expected = ColumnVector::quick([5.666666666666667, 4.333333333333333, 1.6666666666666667]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2322,7 +2325,7 @@ public function quantile() : void $expected = ColumnVector::quick([6.200000000000001, 2.8000000000000003, -6.6]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2340,7 +2343,7 @@ public function variance() : void $expected = ColumnVector::quick([273.55555555555554, 28.222222222222225, 169.55555555555554]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2362,7 +2365,7 @@ public function covariance() : void [135.2222222222222, 3.4444444444444406, 169.55555555555554], ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2384,7 +2387,7 @@ public function round() : void [20, -6, -9], ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -2448,7 +2451,7 @@ public function l1Norm() : void [20.0, -6.0, -9.0], ]); - $this->assertEquals(46.0, $a->l1Norm()); + $this->assertEqualsWithDelta(46.0, $a->l1Norm(), self::MAX_DELTA); } /** @@ -2462,7 +2465,7 @@ public function l2Norm() : void [20.0, -6.0, -9.0], ]); - $this->assertEquals(39.68626966596886, $a->l2Norm()); + $this->assertEqualsWithDelta(39.68626966596886, $a->l2Norm(), self::MAX_DELTA); } /** @@ -2476,7 +2479,7 @@ public function infinityNorm() : void [20.0, -6.0, -9.0], ]); - $this->assertEquals(51.0, $a->infinityNorm()); + $this->assertEqualsWithDelta(51.0, $a->infinityNorm(), self::MAX_DELTA); } /** @@ -2490,7 +2493,7 @@ public function maxNorm() : void [20.0, -6.0, -9.0], ]); - $this->assertEquals(22.0, $a->maxNorm()); + $this->assertEqualsWithDelta(22.0, $a->maxNorm(), self::MAX_DELTA); } /** diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 9421d45..75b5f73 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -21,6 +21,13 @@ */ class VectorTest extends TestCase { + /** + * The maximum error tolerated due to varying numerical precision. + * + * @var float + */ + protected const MAX_DELTA = 1e-8; + /** * @test */ @@ -227,10 +234,11 @@ public function asRowMatrix() : void $matrix = $vector->asRowMatrix(); - $expected = [[-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]]; + $expected = Matrix::quick([ + [-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0], + ]); - $this->assertInstanceOf(Matrix::class, $matrix); - $this->assertEquals($expected, $matrix->asArray()); + $this->assertEquals($expected, $matrix); } /** @@ -312,7 +320,7 @@ public function reciprocal() : void -0.013888888888888888, 0.011235955056179775, 0.009433962264150943, 0.022222222222222223, ]); - $this->assertEquals($expected, $vector); + $this->assertEqualsWithDelta($expected, $vector, self::MAX_DELTA); } /** @@ -326,7 +334,7 @@ public function dot() : void $c = $a->dot($b); - $this->assertEquals(331.54999999999995, $c); + $this->assertEqualsWithDelta(331.54999999999995, $c, self::MAX_DELTA); } public function matmul() : void @@ -348,7 +356,7 @@ public function matmul() : void [622.3751, 4.634999999999993, 40.807], ]); - $this->assertEqualsWithDelta($expected, $c, 1e-8); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -362,7 +370,7 @@ public function inner() : void $c = $a->inner($b); - $this->assertEquals(331.54999999999995, $c); + $this->assertEqualsWithDelta(331.54999999999995, $c, self::MAX_DELTA); } /** @@ -387,7 +395,7 @@ public function outer() : void [11.25, 4.5, 90.0, -22.5, -45.0, -135.0, 148.5, 90.], ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -406,7 +414,7 @@ public function convolve() : void 10.000000000000114, 1764.3000000000002, 1625.1, 2234.7, 1378.4, 535.5, ]); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -421,7 +429,7 @@ public function multiply(Vector $a, $b, $expected) : void { $c = $a->multiply($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -468,7 +476,7 @@ public function divide(Vector $a, $b, $expected) : void { $c = $a->divide($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -515,7 +523,7 @@ public function add(Vector $a, $b, $expected) : void { $c = $a->add($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -562,7 +570,7 @@ public function subtract(Vector $a, $b, $expected) : void { $c = $a->subtract($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -609,7 +617,7 @@ public function power(Vector $a, $b, $expected) : void { $c = $a->pow($b); - $this->assertEquals($expected, $c); + $this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA); } /** @@ -987,7 +995,7 @@ public function square() : void $expected = Vector::quick([225, 625, 1225, 1296, 5184, 7921, 11236, 2025]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1001,7 +1009,7 @@ public function pow() : void $expected = Vector::quick([-3375, 15625, 42875, -46656, -373248, 704969, 1191016, 91125]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1018,7 +1026,7 @@ public function sqrt() : void 1.61245154965971, 3.449637662132068, ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1035,7 +1043,7 @@ public function exp() : void 485165195.4097903, 13.463738035001692, 147266.6252405527, ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1052,7 +1060,7 @@ public function log() : void 2.995732273553991, 0.9555114450274363, 2.4765384001174837, ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1069,7 +1077,7 @@ public function sin() : void 0.9129452507276277, 0.5155013718214642, -0.6181371122370333, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1085,7 +1093,7 @@ public function asin() : void 0.1001674211615598, 0.3046926540153975, -0.5235987755982989, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1102,7 +1110,7 @@ public function cos() : void 0.40808206181339196, -0.8568887533689473, 0.7860702961410393, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1118,7 +1126,7 @@ public function acos() : void 1.4706289056333368, 1.2661036727794992, 2.0943951023931957, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1135,7 +1143,7 @@ public function tan() : void 2.237160944224742, -0.6015966130897586, -0.7863636563696398, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1152,7 +1160,7 @@ public function atan() : void 1.5208379310729538, 1.2036224929766774, 1.486959684726482, ]); - $this->assertEqualsWithDelta($expected, $b, 1e-8); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1169,7 +1177,7 @@ public function rad2deg() : void 1145.9155902616465, 148.96902673401405, 681.8197762056797, ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1186,7 +1194,7 @@ public function deg2rad() : void 0.3490658503988659, 0.04537856055185257, 0.2076941809873252, ]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1196,7 +1204,7 @@ public function sum() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(177.0, $a->sum()); + $this->assertEqualsWithDelta(177.0, $a->sum(), self::MAX_DELTA); } /** @@ -1206,7 +1214,7 @@ public function product() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(-14442510600000.0, $a->product()); + $this->assertEqualsWithDelta(-14442510600000.0, $a->product(), self::MAX_DELTA); } /** @@ -1236,7 +1244,7 @@ public function mean() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(22.125, $a->mean()); + $this->assertEqualsWithDelta(22.125, $a->mean(), self::MAX_DELTA); } /** @@ -1256,7 +1264,7 @@ public function quantile() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(30.0, $a->quantile(0.5)); + $this->assertEqualsWithDelta(30.0, $a->quantile(0.5), self::MAX_DELTA); } /** @@ -1266,7 +1274,7 @@ public function variance() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(3227.609375, $a->variance()); + $this->assertEqualsWithDelta(3227.609375, $a->variance(), self::MAX_DELTA); } /** @@ -1280,7 +1288,7 @@ public function round() : void $expected = Vector::quick([4.0, 6.5, 2.9, 20.0, 2.6, 11.9]); - $this->assertEquals($expected, $b); + $this->assertEqualsWithDelta($expected, $b, self::MAX_DELTA); } /** @@ -1318,7 +1326,7 @@ public function l1Norm() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(423.0, $a->l1Norm()); + $this->assertEqualsWithDelta(423.0, $a->l1Norm(), self::MAX_DELTA); } /** @@ -1328,7 +1336,7 @@ public function l2Norm() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(172.4441938715247, $a->l2Norm()); + $this->assertEqualsWithDelta(172.4441938715247, $a->l2Norm(), self::MAX_DELTA); } /** @@ -1338,7 +1346,7 @@ public function pNorm() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(135.15554088861361, $a->pNorm(3.0)); + $this->assertEqualsWithDelta(135.15554088861361, $a->pNorm(3.0), self::MAX_DELTA); } /** @@ -1348,7 +1356,7 @@ public function maxNorm() : void { $a = Vector::quick([-15.0, 25.0, 35.0, -36.0, -72.0, 89.0, 106.0, 45.0]); - $this->assertEquals(106.0, $a->maxNorm()); + $this->assertEqualsWithDelta(106.0, $a->maxNorm(), self::MAX_DELTA); } /**