Skip to content

Commit 5a403ae

Browse files
committed
Add tests for coordinates validity
1 parent b2b68ed commit 5a403ae

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

test/OpenLocationCodeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function testCorrectCodeFromCoordinates(float $latitude, float $longitude
4646
$resultCode = $floatCal->encode($latitude, $longitude, OpenLocationCode::CODE_PRECISION_NORMAL);
4747
$this->assertEquals($resultCode, $expectedCode);
4848
$resultCodeArea = $floatCal->decode($expectedCode);
49+
$this->confirmCoordinatesValidity($resultCodeArea->northLatitude, $resultCodeArea->eastLongitude);
50+
$this->confirmCoordinatesValidity($resultCodeArea->southLatitude, $resultCodeArea->westLongitude);
4951
$this->assertTrue($resultCodeArea->contains($latitude, $longitude));
5052
if (PHP_INT_SIZE >= 8) {
5153
// at least 64-bit, which means we can use "long" ints here
@@ -57,6 +59,16 @@ public function testCorrectCodeFromCoordinates(float $latitude, float $longitude
5759
}
5860
}
5961

62+
private function confirmCoordinatesValidity(float $latitude, float $longitude): void
63+
{
64+
// check latitude
65+
$this->assertGreaterThanOrEqual(-90, $latitude);
66+
$this->assertLessThanOrEqual(90, $latitude);
67+
// check longitude
68+
$this->assertGreaterThanOrEqual(-180, $longitude);
69+
$this->assertLessThanOrEqual(180, $longitude);
70+
}
71+
6072
public static function codeValidityProvider(): array
6173
{
6274
return [

0 commit comments

Comments
 (0)