diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index 80215b859..0bb1ef8de 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -91,6 +91,7 @@ state-of-tic-tac-toe strain sublist swift-scheduling +tournament triangle twelve-days two-bucket diff --git a/config.json b/config.json index 8f612eda4..39af61436 100644 --- a/config.json +++ b/config.json @@ -969,18 +969,6 @@ "prerequisites": [], "difficulty": 3 }, - { - "slug": "tournament", - "name": "Tournament", - "uuid": "e0572cf4-5481-4da4-bf9b-0e921cb81627", - "practices": [], - "prerequisites": [], - "difficulty": 3, - "topics": [ - "parsing", - "strings" - ] - }, { "slug": "bob", "name": "Bob", @@ -1138,6 +1126,18 @@ "prerequisites": [], "difficulty": 4 }, + { + "slug": "tournament", + "name": "Tournament", + "uuid": "e0572cf4-5481-4da4-bf9b-0e921cb81627", + "practices": [], + "prerequisites": [], + "difficulty": 4, + "topics": [ + "parsing", + "strings" + ] + }, { "slug": "alphametics", "name": "Alphametics", diff --git a/exercises/practice/tournament/.docs/instructions.md b/exercises/practice/tournament/.docs/instructions.md index 8831dd195..e5ca23738 100644 --- a/exercises/practice/tournament/.docs/instructions.md +++ b/exercises/practice/tournament/.docs/instructions.md @@ -2,8 +2,7 @@ Tally the results of a small football competition. -Based on an input file containing which team played against which and what the -outcome was, create a file with a table like this: +Based on an input file containing which team played against which and what the outcome was, create a file with a table like this: ```text Team | MP | W | D | L | P @@ -21,9 +20,12 @@ What do those abbreviations mean? - L: Matches Lost - P: Points -A win earns a team 3 points. A draw earns 1. A loss earns 0. +A win earns a team 3 points. +A draw earns 1. +A loss earns 0. -The outcome should be ordered by points, descending. In case of a tie, teams are ordered alphabetically. +The outcome is ordered by points, descending. +In case of a tie, teams are ordered alphabetically. ## Input @@ -38,7 +40,8 @@ Blithering Badgers;Devastating Donkeys;loss Allegoric Alaskans;Courageous Californians;win ``` -The result of the match refers to the first team listed. So this line: +The result of the match refers to the first team listed. +So this line: ```text Allegoric Alaskans;Blithering Badgers;win diff --git a/exercises/practice/tournament/.meta/config.json b/exercises/practice/tournament/.meta/config.json index 404e75dfb..3b7d54413 100644 --- a/exercises/practice/tournament/.meta/config.json +++ b/exercises/practice/tournament/.meta/config.json @@ -3,7 +3,8 @@ "MichaelBunker" ], "contributors": [ - "dstockto" + "dstockto", + "resu-xuniL" ], "files": { "solution": [ diff --git a/exercises/practice/tournament/.meta/example.php b/exercises/practice/tournament/.meta/example.php index f5da28e82..5a4cd07d5 100644 --- a/exercises/practice/tournament/.meta/example.php +++ b/exercises/practice/tournament/.meta/example.php @@ -1,33 +1,11 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); class Tournament { private string $header = "Team | MP | W | D | L | P\n"; - private string $teamRow = "%s | %d | %d | %d | %d | %d\n"; + private string $teamRow = "%s |%3d |%3d |%3d |%3d |%3d\n"; public function tally(string $scores): string { diff --git a/exercises/practice/tournament/.meta/tests.toml b/exercises/practice/tournament/.meta/tests.toml new file mode 100644 index 000000000..0e33c87fc --- /dev/null +++ b/exercises/practice/tournament/.meta/tests.toml @@ -0,0 +1,46 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[67e9fab1-07c1-49cf-9159-bc8671cc7c9c] +description = "just the header if no input" + +[1b4a8aef-0734-4007-80a2-0626178c88f4] +description = "a win is three points, a loss is zero points" + +[5f45ac09-4efe-46e7-8ddb-75ad85f86e05] +description = "a win can also be expressed as a loss" + +[fd297368-efa0-442d-9f37-dd3f9a437239] +description = "a different team can win" + +[26c016f9-e753-4a93-94e9-842f7b4d70fc] +description = "a draw is one point each" + +[731204f6-4f34-4928-97eb-1c307ba83e62] +description = "There can be more than one match" + +[49dc2463-42af-4ea6-95dc-f06cc5776adf] +description = "There can be more than one winner" + +[6d930f33-435c-4e6f-9e2d-63fa85ce7dc7] +description = "There can be more than two teams" + +[97022974-0c8a-4a50-8fe7-e36bdd8a5945] +description = "typical input" + +[fe562f0d-ac0a-4c62-b9c9-44ee3236392b] +description = "incomplete competition (not all pairs have played)" + +[3aa0386f-150b-4f99-90bb-5195e7b7d3b8] +description = "ties broken alphabetically" + +[f9e20931-8a65-442a-81f6-503c0205b17a] +description = "ensure points sorted numerically" diff --git a/exercises/practice/tournament/TournamentTest.php b/exercises/practice/tournament/TournamentTest.php index 1b107ed87..098b24874 100644 --- a/exercises/practice/tournament/TournamentTest.php +++ b/exercises/practice/tournament/TournamentTest.php @@ -1,30 +1,9 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\TestDox; class TournamentTest extends TestCase { @@ -40,14 +19,22 @@ protected function setUp(): void $this->tournament = new Tournament(); } - public function testHeaderOnlyNoTeams(): void + /** + * uuid: 67e9fab1-07c1-49cf-9159-bc8671cc7c9c + */ + #[TestDox('Just the header if no input')] + public function testJustTheHeaderIfNoInput(): void { $scores = ''; $expected = 'Team | MP | W | D | L | P'; $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testWinIsThreePointsLossIsZeroPoints(): void + /** + * uuid: 1b4a8aef-0734-4007-80a2-0626178c88f4 + */ + #[TestDox('A win is three points, a loss is zero points')] + public function testAWinIsThreePointsALossIsZeroPoints(): void { $scores = 'Allegoric Alaskans;Blithering Badgers;win'; $expected = @@ -57,7 +44,11 @@ public function testWinIsThreePointsLossIsZeroPoints(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testWinCanAlsoBeExpressedAsALoss(): void + /** + * uuid: 5f45ac09-4efe-46e7-8ddb-75ad85f86e05 + */ + #[TestDox('A win can also be expressed as a loss')] + public function testAWinCanAlsoBeExpressedAsALoss(): void { $scores = 'Blithering Badgers;Allegoric Alaskans;loss'; $expected = @@ -67,7 +58,11 @@ public function testWinCanAlsoBeExpressedAsALoss(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testDifferentTeamsCanWin(): void + /** + * uuid: fd297368-efa0-442d-9f37-dd3f9a437239 + */ + #[TestDox('A different team can win')] + public function testADifferentTeamCanWin(): void { $scores = 'Blithering Badgers;Allegoric Alaskans;win'; $expected = @@ -77,6 +72,10 @@ public function testDifferentTeamsCanWin(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } + /** + * uuid: 26c016f9-e753-4a93-94e9-842f7b4d70fc + */ + #[TestDox('A draw is one point each')] public function testADrawIsOnePointEach(): void { $scores = 'Allegoric Alaskans;Blithering Badgers;draw'; @@ -87,7 +86,11 @@ public function testADrawIsOnePointEach(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testThereCanBeMultipleMatches(): void + /** + * uuid: 731204f6-4f34-4928-97eb-1c307ba83e62 + */ + #[TestDox('There can be more than one match')] + public function testThereCanBeMoreThanOneMatch(): void { $scores = "Allegoric Alaskans;Blithering Badgers;win\n" . @@ -99,6 +102,10 @@ public function testThereCanBeMultipleMatches(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } + /** + * uuid: 49dc2463-42af-4ea6-95dc-f06cc5776adf + */ + #[TestDox('There can be more than one winner')] public function testThereCanBeMoreThanOneWinner(): void { $scores = @@ -111,6 +118,10 @@ public function testThereCanBeMoreThanOneWinner(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } + /** + * uuid: 6d930f33-435c-4e6f-9e2d-63fa85ce7dc7 + */ + #[TestDox('There can be more than two teams')] public function testThereCanBeMoreThanTwoTeams(): void { $scores = @@ -125,7 +136,11 @@ public function testThereCanBeMoreThanTwoTeams(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testStandardInput(): void + /** + * uuid: 97022974-0c8a-4a50-8fe7-e36bdd8a5945 + */ + #[TestDox('Typical input')] + public function testTypicalInput(): void { $scores = "Allegoric Alaskans;Blithering Badgers;win\n" . @@ -143,7 +158,11 @@ public function testStandardInput(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testIncompleteCompetitionWhereNotAllGamesPlayed(): void + /** + * uuid: fe562f0d-ac0a-4c62-b9c9-44ee3236392b + */ + #[TestDox('Incomplete competition (not all pairs have played)')] + public function testIncompleteCompetitionNotAllPairsHavePlayed(): void { $scores = "Allegoric Alaskans;Blithering Badgers;loss\n" . @@ -159,7 +178,11 @@ public function testIncompleteCompetitionWhereNotAllGamesPlayed(): void $this->assertEquals($expected, $this->tournament->tally($scores)); } - public function testTiesSortedAlphabetically(): void + /** + * uuid: 3aa0386f-150b-4f99-90bb-5195e7b7d3b8 + */ + #[TestDox('Ties broken alphabetically')] + public function testTiesBrokenAlphabetically(): void { $scores = "Courageous Californians;Devastating Donkeys;win\n" . @@ -176,4 +199,23 @@ public function testTiesSortedAlphabetically(): void "Devastating Donkeys | 3 | 0 | 1 | 2 | 1"; $this->assertEquals($expected, $this->tournament->tally($scores)); } + + /** + * uuid: f9e20931-8a65-442a-81f6-503c0205b17a + */ + #[TestDox('Ensure points sorted numerically')] + public function testEnsurePointsSortedNumerically(): void + { + $scores = + "Devastating Donkeys;Blithering Badgers;win\n" . + "Devastating Donkeys;Blithering Badgers;win\n" . + "Devastating Donkeys;Blithering Badgers;win\n" . + "Devastating Donkeys;Blithering Badgers;win\n" . + "Blithering Badgers;Devastating Donkeys;win"; + $expected = + "Team | MP | W | D | L | P\n" . + "Devastating Donkeys | 5 | 4 | 0 | 1 | 12\n" . + "Blithering Badgers | 5 | 1 | 0 | 4 | 3"; + $this->assertEquals($expected, $this->tournament->tally($scores)); + } }