Skip to content

Commit 5beb644

Browse files
committed
Test code calculator encode()
1 parent 8a54aa2 commit 5beb644

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/OpenLocationCodeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use InvalidArgumentException;
66
use PHPUnit\Framework\Attributes\DataProvider;
77
use PHPUnit\Framework\TestCase;
8+
use Vectorial1024\OpenLocationCodePhp\CodeCalculator\CodeCalculatorFloat;
9+
use Vectorial1024\OpenLocationCodePhp\CodeCalculator\CodeCalculatorInt;
810
use Vectorial1024\OpenLocationCodePhp\OpenLocationCode;
911

1012
class OpenLocationCodeTest extends TestCase
@@ -38,6 +40,17 @@ public function testCorrectCodeFromCoordinates(float $latitude, float $longitude
3840
$this->assertEquals($expectedCode, $codeObject->code);
3941
// while OLC represents an area via lossful encoding, at least the area should contain the original point
4042
$this->assertTrue($codeObject->contains($latitude, $longitude));
43+
44+
// for convenience, also test the code calculators here
45+
$floatCal = new CodeCalculatorFloat();
46+
$resultCode = $floatCal->encode($latitude, $longitude, OpenLocationCode::CODE_PRECISION_NORMAL);
47+
$this->assertEquals($resultCode, $expectedCode);
48+
if (PHP_INT_SIZE >= 8) {
49+
// at least 64-bit, which means we can use "long" ints here
50+
$intCal = new CodeCalculatorInt();
51+
$resultCode = $intCal->encode($latitude, $longitude, OpenLocationCode::CODE_PRECISION_NORMAL);
52+
$this->assertEquals($resultCode, $expectedCode);
53+
}
4154
}
4255

4356
public static function codeValidityProvider(): array

0 commit comments

Comments
 (0)