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
1 change: 1 addition & 0 deletions bin/auto-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ state-of-tic-tac-toe
strain
sublist
swift-scheduling
tournament
triangle
twelve-days
two-bucket
Expand Down
24 changes: 12 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions exercises/practice/tournament/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion exercises/practice/tournament/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"MichaelBunker"
],
"contributors": [
"dstockto"
"dstockto",
"resu-xuniL"
],
"files": {
"solution": [
Expand Down
24 changes: 1 addition & 23 deletions exercises/practice/tournament/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* 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
{
Expand Down
46 changes: 46 additions & 0 deletions exercises/practice/tournament/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
102 changes: 72 additions & 30 deletions exercises/practice/tournament/TournamentTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* 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
{
Expand All @@ -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 =
Expand All @@ -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 =
Expand All @@ -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 =
Expand All @@ -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';
Expand All @@ -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" .
Expand All @@ -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 =
Expand All @@ -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 =
Expand All @@ -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" .
Expand All @@ -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" .
Expand All @@ -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" .
Expand All @@ -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));
}
}
Loading