@@ -26,15 +26,13 @@ public function testCorrectCodeValidity(?string $testCode, bool $expectedValidit
2626 }
2727 }
2828
29- public function testCorrectCodeFromCoordinates ()
29+ #[DataProvider('encodingProvider ' )]
30+ public function testCorrectCodeFromCoordinates (float $ latitude , float $ longitude , string $ expectedCode )
3031 {
31- // test King's Cross for now; later may expand to see more test cases
32- $ kingsCrossLat = 51.530812 ;
33- $ kingsCrossLng = -0.123767 ;
34- $ kingsCrossCode = "9C3XGVJG+8F " ;
35-
36- $ codeObject = OpenLocationCode::createFromCoordinates ($ kingsCrossLat , $ kingsCrossLng );
37- $ this ->assertEquals ($ kingsCrossCode , $ codeObject ->code );
32+ $ codeObject = OpenLocationCode::createFromCoordinates ($ latitude , $ longitude );
33+ $ this ->assertEquals ($ expectedCode , $ codeObject ->code );
34+ // while OLC represents an area via lossful encoding, at least the area should contain the original point
35+ $ this ->assertTrue ($ codeObject ->contains ($ latitude , $ longitude ));
3836 }
3937
4038 public static function codeValidityProvider (): array
@@ -47,4 +45,18 @@ public static function codeValidityProvider(): array
4745 "London King's Cross, London " => ["9C3XGVJG+8F " , true ],
4846 ];
4947 }
48+
49+ public static function encodingProvider (): array
50+ {
51+ // latitude, longitude, expected code (check the external demo)
52+ return [
53+ "London King's Cross, London " => [51.530812 , -0.123767 , "9C3XGVJG+8F " ],
54+ "Changi Airport, Singapore " => [1.357063 , 103.988563 , "6PH59X4Q+RC " ],
55+ "International Antarctic Centre, Christchurch " => [-43.489063 , 172.547188 , "4V8JGG6W+9V " ],
56+ "Christo Redentor, Rio de Janeiro " => [-22.951937 , -43.210437 , "589R2QXQ+6R " ],
57+ "New Chitose Airport, Chitose " => [42.786062 ,141.680937 , "8RJ3QMPJ+C9 " ],
58+ "Berling Strait " => [65.759937 , -169.149437 , "92QGQV52+X6 " ],
59+ "Null point " => [0 , 0 , "6FG22222+22 " ],
60+ ];
61+ }
5062}
0 commit comments