From e033b732fe238d11c8451c76d6372bfab56c8daf Mon Sep 17 00:00:00 2001 From: Kevin Wenger Date: Wed, 12 Jul 2023 11:01:46 +0200 Subject: [PATCH] use assertion with Delta on PHPUnit float values --- CHANGELOG.md | 1 + tests/SwisstopoConverterWGSToMN03Tests.php | 10 ++++------ tests/SwisstopoConverterWGSToMN95Tests.php | 10 ++++------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7766e84..ae35575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - update changelog following 'keep a changelog' format - run code-styles Github Actions on PHP 8.1 - update symfony checker to use new symfonycorp/security-checker-action +- use assertion with Delta on PHPUnit float values ### Added - add run of tests on Github Actions diff --git a/tests/SwisstopoConverterWGSToMN03Tests.php b/tests/SwisstopoConverterWGSToMN03Tests.php index b5461b7..5a52a17 100644 --- a/tests/SwisstopoConverterWGSToMN03Tests.php +++ b/tests/SwisstopoConverterWGSToMN03Tests.php @@ -20,10 +20,8 @@ public function testFromMN03ToWGS(): void { $swiss_converter = new SwisstopoConverter(); $coordinates = $swiss_converter->fromMN03ToWGS(554680, 145807); - $this->assertSame([ - 'lat' => 46.462057617639346, - 'long' => 6.848673659076181, - ], $coordinates); + $this->assertEqualsWithDelta(46.462057617639, $coordinates['lat'], 0.0001); + $this->assertEqualsWithDelta(6.8486736590762, $coordinates['long'], 0.0001); } /** @@ -48,7 +46,7 @@ public function testFromMN03ToWGSLatitude(): void { $swiss_converter = new SwisstopoConverter(); $latitude = $this->invokeMethod($swiss_converter, 'fromMN03ToWGSLatitude', [554680, 145807]); - $this->assertEquals(46.462057617639, $latitude); + $this->assertEqualsWithDelta(46.462057617639, $latitude, 0.0001); } /** @@ -60,7 +58,7 @@ public function testFromMN03ToWGSLongitude(): void { $swiss_converter = new SwisstopoConverter(); $longitude = $this->invokeMethod($swiss_converter, 'fromMN03ToWGSLongitude', [554680, 145807]); - $this->assertEquals(6.8486736590762, $longitude); + $this->assertEqualsWithDelta(6.8486736590762, $longitude, 0.0001); } /** diff --git a/tests/SwisstopoConverterWGSToMN95Tests.php b/tests/SwisstopoConverterWGSToMN95Tests.php index a60c4a4..264568a 100644 --- a/tests/SwisstopoConverterWGSToMN95Tests.php +++ b/tests/SwisstopoConverterWGSToMN95Tests.php @@ -20,10 +20,8 @@ public function testFromMN95ToWGS(): void { $swiss_converter = new SwisstopoConverter(); $coordinates = $swiss_converter->fromMN95ToWGS(2555047, 1145923); - $this->assertSame([ - 'lat' => 46.46312579498212, - 'long' => 6.8534397262208095, - ], $coordinates); + $this->assertEqualsWithDelta(46.463125794982, $coordinates['lat'], 0.0001); + $this->assertEqualsWithDelta(6.8534397262208, $coordinates['long'], 0.0001); } /** @@ -74,7 +72,7 @@ public function testFromMN95ToWGSLatitude(): void { $swiss_converter = new SwisstopoConverter(); $latitude = $this->invokeMethod($swiss_converter, 'fromMN95ToWGSLatitude', [2555047, 1145923]); - $this->assertEquals(46.463125794982, $latitude); + $this->assertEqualsWithDelta(46.463125794982, $latitude, 0.0001); } /** @@ -86,6 +84,6 @@ public function testFromMN95ToWGSLongitude(): void { $swiss_converter = new SwisstopoConverter(); $longitude = $this->invokeMethod($swiss_converter, 'fromMN95ToWGSLongitude', [2555047, 1145923]); - $this->assertEquals(6.8534397262208, $longitude); + $this->assertEqualsWithDelta(6.8534397262208, $longitude, 0.0001); } }