Skip to content

Commit

Permalink
Provide more test cases
Browse files Browse the repository at this point in the history
Also tests more methods
  • Loading branch information
Vectorial1024 committed Oct 3, 2024
1 parent b2b047a commit 5f237cc
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions test/OpenLocationCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public function testCorrectCodeValidity(?string $testCode, bool $expectedValidit
}
}

public function testCorrectCodeFromCoordinates()
#[DataProvider('encodingProvider')]
public function testCorrectCodeFromCoordinates(float $latitude, float $longitude, string $expectedCode)
{
// test King's Cross for now; later may expand to see more test cases
$kingsCrossLat = 51.530812;
$kingsCrossLng = -0.123767;
$kingsCrossCode = "9C3XGVJG+8F";

$codeObject = OpenLocationCode::createFromCoordinates($kingsCrossLat, $kingsCrossLng);
$this->assertEquals($kingsCrossCode, $codeObject->code);
$codeObject = OpenLocationCode::createFromCoordinates($latitude, $longitude);
$this->assertEquals($expectedCode, $codeObject->code);
// while OLC represents an area via lossful encoding, at least the area should contain the original point
$this->assertTrue($codeObject->contains($latitude, $longitude));
}

public static function codeValidityProvider(): array
Expand All @@ -47,4 +45,18 @@ public static function codeValidityProvider(): array
"London King's Cross, London" => ["9C3XGVJG+8F", true],
];
}

public static function encodingProvider(): array
{
// latitude, longitude, expected code (check the external demo)
return [
"London King's Cross, London" => [51.530812, -0.123767, "9C3XGVJG+8F"],
"Changi Airport, Singapore" => [1.357063, 103.988563, "6PH59X4Q+RC"],
"International Antarctic Centre, Christchurch" => [-43.489063, 172.547188, "4V8JGG6W+9V"],
"Christo Redentor, Rio de Janeiro" => [-22.951937, -43.210437, "589R2QXQ+6R"],
"New Chitose Airport, Chitose" => [42.786062,141.680937, "8RJ3QMPJ+C9"],
"Berling Strait" => [65.759937, -169.149437, "92QGQV52+X6"],
"Null point" => [0, 0, "6FG22222+22"],
];
}
}

0 comments on commit 5f237cc

Please sign in to comment.