diff --git a/src/Points.php b/src/Points.php index 84dea3b..b25754c 100644 --- a/src/Points.php +++ b/src/Points.php @@ -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, @@ -19,9 +19,9 @@ 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']; } @@ -29,9 +29,9 @@ function getX($point): int /** * 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']; } diff --git a/tests/PointsTest.php b/tests/PointsTest.php index af625ab..1786924 100644 --- a/tests/PointsTest.php +++ b/tests/PointsTest.php @@ -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);