Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Points.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

/**
* Creates a point with two coordinates
* @param int $x
* @param int $y
* @param int|float $x
* @param int|float $y
* @return array
*/
function makePoint(int $x, int $y): array
function makePoint(int|float $x, int|float $y): array
{
return [
'x' => $x,
Expand All @@ -19,19 +19,19 @@ function makePoint(int $x, int $y): array
/**
* Extracts x coordinate from point
* @param array $point
* @return int
* @return int|float
*/
function getX($point): int
function getX(array $point): int|float
{
return $point['x'];
}

/**
* Extracts y coordinate from point
* @param array $point
* @return int
* @return int|float
*/
function getY(array $point): int
function getY(array $point): int|float
{
return $point['y'];
}
Expand Down
10 changes: 10 additions & 0 deletions tests/PointsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public function testMakePoints(): void
$this->assertEquals(0, getY($points2));
}

public function testFloatCoordinates(): void
{
$point = makePoint(-1.5, 0);

$this->assertSame(-1.5, getX($point));
$this->assertSame(0, getY($point));
$this->assertEquals("(-1.5, 0)", toString($point));
$this->assertEquals(null, getQuadrant($point));
}

public function testToString(): void
{
$points1 = makePoint(1, 8);
Expand Down
Loading