diff --git a/exercises/practice/darts/.meta/example.php b/exercises/practice/darts/.meta/example.php index b827d711..8417a832 100644 --- a/exercises/practice/darts/.meta/example.php +++ b/exercises/practice/darts/.meta/example.php @@ -2,29 +2,19 @@ declare(strict_types=1); -class Darts +function calculateScore(float $xAxis, float $yAxis): int { - public int $score = 0; + $location = $xAxis ** 2 + $yAxis ** 2; - public function __construct(float $xAxis, float $yAxis) - { - $this->score = $this->calculateScore($xAxis, $yAxis); + if ($location > 100) { + return 0; } - - private function calculateScore(float $xAxis, float $yAxis): int - { - $location = $xAxis ** 2 + $yAxis ** 2; - - if ($location > 100) { - return 0; - } - if ($location > 25) { - return 1; - } - if ($location > 1) { - return 5; - } - - return 10; + if ($location > 25) { + return 1; } + if ($location > 1) { + return 5; + } + + return 10; } diff --git a/exercises/practice/darts/Darts.php b/exercises/practice/darts/Darts.php index 7811b53d..8f4918e2 100644 --- a/exercises/practice/darts/Darts.php +++ b/exercises/practice/darts/Darts.php @@ -24,12 +24,7 @@ declare(strict_types=1); -class Darts +function __construct(float $xAxis, float $yAxis) { - public int $score = 0; - - public function __construct(float $xAxis, float $yAxis) - { - throw new BadFunctionCallException("Please implement the Darts class!"); - } + throw new BadFunctionCallException("Please implement the Darts class!"); } diff --git a/exercises/practice/darts/DartsTest.php b/exercises/practice/darts/DartsTest.php index 83055531..05c2814e 100644 --- a/exercises/practice/darts/DartsTest.php +++ b/exercises/practice/darts/DartsTest.php @@ -15,8 +15,7 @@ public static function setUpBeforeClass(): void */ public function testMissedTarget(): void { - $board = new Darts(-9, 9); - $this->assertEquals(0, $board->score); + $this->assertEquals(0, calculateScore(-9.0, 9.0)); } /** @@ -25,8 +24,7 @@ public function testMissedTarget(): void */ public function testInOuterCircle(): void { - $board = new Darts(0, 10); - $this->assertEquals(1, $board->score); + $this->assertEquals(1, calculateScore(0.0, 10.0)); } /** @@ -35,8 +33,7 @@ public function testInOuterCircle(): void */ public function testInMiddleCircle(): void { - $board = new Darts(-5, 0); - $this->assertEquals(5, $board->score); + $this->assertEquals(5, calculateScore(-5.0, 0.0)); } /** @@ -45,8 +42,7 @@ public function testInMiddleCircle(): void */ public function testInInnerCircle(): void { - $board = new Darts(0, -1); - $this->assertEquals(10, $board->score); + $this->assertEquals(10, calculateScore(0.0, -1.0)); } /** @@ -55,8 +51,7 @@ public function testInInnerCircle(): void */ public function testInCenter(): void { - $board = new Darts(0, 0); - $this->assertEquals(10, $board->score); + $this->assertEquals(10, calculateScore(0.0, 0.0)); } /** @@ -65,8 +60,7 @@ public function testInCenter(): void */ public function testNearCenter(): void { - $board = new Darts(-0.1, -0.1); - $this->assertEquals(10, $board->score); + $this->assertEquals(10, calculateScore(-0.1, -0.1)); } /** @@ -75,8 +69,7 @@ public function testNearCenter(): void */ public function testJustInsideCenter(): void { - $board = new Darts(0.7, 0.7); - $this->assertEquals(10, $board->score); + $this->assertEquals(10, calculateScore(0.7, 0.7)); } /** @@ -85,8 +78,7 @@ public function testJustInsideCenter(): void */ public function testJustOutsideCenter(): void { - $board = new Darts(0.8, -0.8); - $this->assertEquals(5, $board->score); + $this->assertEquals(5, calculateScore(0.8, -0.8)); } /** @@ -95,8 +87,7 @@ public function testJustOutsideCenter(): void */ public function testJustWithinMiddleCircle(): void { - $board = new Darts(-3.5, 3.5); - $this->assertEquals(5, $board->score); + $this->assertEquals(5, calculateScore(-3.5, 3.5)); } /** @@ -105,8 +96,7 @@ public function testJustWithinMiddleCircle(): void */ public function testJustOutsideMiddleCircle(): void { - $board = new Darts(-3.6, -3.6); - $this->assertEquals(1, $board->score); + $this->assertEquals(1, calculateScore(-3.6, -3.6)); } /** @@ -115,8 +105,7 @@ public function testJustOutsideMiddleCircle(): void */ public function testJustInsideOuterCircle(): void { - $board = new Darts(-7.0, 7.0); - $this->assertEquals(1, $board->score); + $this->assertEquals(1, calculateScore(-7.0, 7.0)); } /** @@ -125,8 +114,7 @@ public function testJustInsideOuterCircle(): void */ public function testJustOutsideOuterCircle(): void { - $board = new Darts(7.1, -7.1); - $this->assertEquals(0, $board->score); + $this->assertEquals(0, calculateScore(7.1, -7.1)); } /** @@ -135,7 +123,6 @@ public function testJustOutsideOuterCircle(): void */ public function testAsymmetricPositionBetweenInnerAndOuterCircles(): void { - $board = new Darts(0.5, -4); - $this->assertEquals(5, $board->score); + $this->assertEquals(5, calculateScore(0.5, -4)); } }