From bfc558d1f267beede27ab56d759764fb80032306 Mon Sep 17 00:00:00 2001 From: Alex Wulf Date: Tue, 5 Jul 2022 15:46:45 +0200 Subject: [PATCH] Some tests converted to new syntax --- tests/Numerics/GaussianDistributionTest.php | 30 ++++++++++----------- tests/TrueSkill/DrawMarginTest.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Numerics/GaussianDistributionTest.php b/tests/Numerics/GaussianDistributionTest.php index ac42c33..e09416e 100644 --- a/tests/Numerics/GaussianDistributionTest.php +++ b/tests/Numerics/GaussianDistributionTest.php @@ -12,14 +12,14 @@ class GaussianDistributionTest extends TestCase { // Verified with WolframAlpha // (e.g. http://www.wolframalpha.com/input/?i=CDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D ) - $this->assertEquals(0.691462, GaussianDistribution::cumulativeTo(0.5), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(0.691462, GaussianDistribution::cumulativeTo(0.5), GaussianDistributionTest::ERROR_TOLERANCE); } public function testAt() { // Verified with WolframAlpha // (e.g. http://www.wolframalpha.com/input/?i=PDF%5BNormalDistribution%5B0%2C1%5D%2C+0.5%5D ) - $this->assertEquals(0.352065, GaussianDistribution::at(0.5), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(0.352065, GaussianDistribution::at(0.5), GaussianDistributionTest::ERROR_TOLERANCE); } public function testMultiplication() @@ -29,8 +29,8 @@ class GaussianDistributionTest extends TestCase $shiftedGaussian = new GaussianDistribution(2, 3); $product = GaussianDistribution::multiply($standardNormal, $shiftedGaussian); - $this->assertEquals(0.2, $product->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE); - $this->assertEquals(3.0 / sqrt(10), $product->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(0.2, $product->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(3.0 / sqrt(10), $product->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE); $m4s5 = new GaussianDistribution(4, 5); $m6s7 = new GaussianDistribution(6, 7); @@ -38,10 +38,10 @@ class GaussianDistributionTest extends TestCase $product2 = GaussianDistribution::multiply($m4s5, $m6s7); $expectedMean = (4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)); - $this->assertEquals($expectedMean, $product2->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta($expectedMean, $product2->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); $expectedSigma = sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7)))); - $this->assertEquals($expectedSigma, $product2->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta($expectedSigma, $product2->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE); } public function testDivision() @@ -51,14 +51,14 @@ class GaussianDistributionTest extends TestCase $standardNormal = new GaussianDistribution(0, 1); $productDividedByStandardNormal = GaussianDistribution::divide($product, $standardNormal); - $this->assertEquals(2.0, $productDividedByStandardNormal->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE); - $this->assertEquals(3.0, $productDividedByStandardNormal->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(2.0, $productDividedByStandardNormal->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(3.0, $productDividedByStandardNormal->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE); $product2 = new GaussianDistribution((4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)), sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7))))); $m4s5 = new GaussianDistribution(4, 5); $product2DividedByM4S5 = GaussianDistribution::divide($product2, $m4s5); - $this->assertEquals(6.0, $product2DividedByM4S5->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE); - $this->assertEquals(7.0, $product2DividedByM4S5->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(6.0, $product2DividedByM4S5->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(7.0, $product2DividedByM4S5->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE); } public function testLogProductNormalization() @@ -66,12 +66,12 @@ class GaussianDistributionTest extends TestCase // Verified with Ralf Herbrich's F# implementation $standardNormal = new GaussianDistribution(0, 1); $lpn = GaussianDistribution::logProductNormalization($standardNormal, $standardNormal); - $this->assertEquals(-1.2655121234846454, $lpn, '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(-1.2655121234846454, $lpn, GaussianDistributionTest::ERROR_TOLERANCE); $m1s2 = new GaussianDistribution(1, 2); $m3s4 = new GaussianDistribution(3, 4); $lpn2 = GaussianDistribution::logProductNormalization($m1s2, $m3s4); - $this->assertEquals(-2.5168046699816684, $lpn2, '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(-2.5168046699816684, $lpn2, GaussianDistributionTest::ERROR_TOLERANCE); } public function testLogRatioNormalization() @@ -80,7 +80,7 @@ class GaussianDistributionTest extends TestCase $m1s2 = new GaussianDistribution(1, 2); $m3s4 = new GaussianDistribution(3, 4); $lrn = GaussianDistribution::logRatioNormalization($m1s2, $m3s4); - $this->assertEquals(2.6157405972171204, $lrn, '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(2.6157405972171204, $lrn, GaussianDistributionTest::ERROR_TOLERANCE); } public function testAbsoluteDifference() @@ -88,11 +88,11 @@ class GaussianDistributionTest extends TestCase // Verified with Ralf Herbrich's F# implementation $standardNormal = new GaussianDistribution(0, 1); $absDiff = GaussianDistribution::absoluteDifference($standardNormal, $standardNormal); - $this->assertEquals(0.0, $absDiff, '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(0.0, $absDiff, GaussianDistributionTest::ERROR_TOLERANCE); $m1s2 = new GaussianDistribution(1, 2); $m3s4 = new GaussianDistribution(3, 4); $absDiff2 = GaussianDistribution::absoluteDifference($m1s2, $m3s4); - $this->assertEquals(0.4330127018922193, $absDiff2, '', GaussianDistributionTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta(0.4330127018922193, $absDiff2, GaussianDistributionTest::ERROR_TOLERANCE); } } \ No newline at end of file diff --git a/tests/TrueSkill/DrawMarginTest.php b/tests/TrueSkill/DrawMarginTest.php index 2f4c565..ff0a32b 100644 --- a/tests/TrueSkill/DrawMarginTest.php +++ b/tests/TrueSkill/DrawMarginTest.php @@ -19,6 +19,6 @@ class DrawMarginTest extends TestCase private function assertDrawMargin($drawProbability, $beta, $expected) { $actual = DrawMargin::getDrawMarginFromDrawProbability($drawProbability, $beta); - $this->assertEquals($expected, $actual, '', DrawMarginTest::ERROR_TOLERANCE); + $this->assertEqualsWithDelta($expected, $actual, DrawMarginTest::ERROR_TOLERANCE); } } \ No newline at end of file