Skip to content

Instantly share code, notes, and snippets.

@CamKem
Last active March 25, 2023 10:39
Show Gist options
  • Save CamKem/f591e492cf5a325299303372dc5c40f5 to your computer and use it in GitHub Desktop.
Save CamKem/f591e492cf5a325299303372dc5c40f5 to your computer and use it in GitHub Desktop.
Test: Tennis Match Kata
<?php
namespace Tests\Feature\Katas;
use Tests\Feature\Katas\TennisMatch;
use PHPUnit\Framework\TestCase;
class TennisMatchTest extends TestCase
{
/**
* @test
* @dataProvider scores
*/
public function it_makes_a_score($playerOnePoints, $playerTwoPoints, $expectedScore)
{
$match = new TennisMatch(
$john = new Player('John'),
$jane = new Player('Jane'),
);
for ($i = 0; $i < $playerOnePoints; $i++) {
$john->scorePoint();
}
for ($i = 0; $i < $playerTwoPoints; $i++) {
$jane->scorePoint();
}
$this->assertEquals($expectedScore, $match->score());
}
public function scores(): array
{
return [
[0, 0, 'love-all'],
[1, 0, 'fifteen-love'],
[2, 0, 'thirty-love'],
[3, 0, 'forty-love'],
[0, 1, 'love-fifteen'],
[0, 2, 'love-thirty'],
[0, 3, 'love-forty'],
[1, 2, 'fifteen-thirty'],
[2, 1, 'thirty-fifteen'],
[3, 2, 'forty-thirty'], // data set 10
[2, 3, 'thirty-forty'],
[1, 1, 'fifteen-all'],
[2, 2, 'thirty-all'],
[3, 3, 'deuce'],
[4, 4, 'deuce'],
[5, 5, 'deuce'],
[6, 6, 'Tie-Breaker'],
[7, 6, 'Winner: John'],
[6, 7, 'Winner: Jane'],
[4, 0, 'Winner: John'],
[0, 4, 'Winner: Jane'],
[4, 1, 'Winner: John'],
[1, 4, 'Winner: Jane'],
[4, 3, 'Advantage: John'],
[3, 4, 'Advantage: Jane'],
[4, 2, 'Winner: John'],
[2, 4, 'Winner: Jane'],
[5, 4, 'Advantage: John'],
[4, 5, 'Advantage: Jane'],
[6, 4, 'Winner: John'],
[4, 6, 'Winner: Jane'],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment