Skip to content

Commit af69bcb

Browse files
committed
Inline instantiation of Tournament
1 parent ebd2f29 commit af69bcb

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

exercises/practice/tournament/TournamentTest.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@
77

88
class TournamentTest extends TestCase
99
{
10-
private Tournament $tournament;
11-
1210
public static function setUpBeforeClass(): void
1311
{
1412
require_once 'Tournament.php';
1513
}
1614

17-
protected function setUp(): void
18-
{
19-
$this->tournament = new Tournament();
20-
}
21-
2215
/**
2316
* uuid: 67e9fab1-07c1-49cf-9159-bc8671cc7c9c
2417
*/
2518
#[TestDox('Just the header if no input')]
2619
public function testJustTheHeaderIfNoInput(): void
2720
{
21+
$tournament = new Tournament();
2822
$scores = '';
2923
$expected = 'Team | MP | W | D | L | P';
30-
$this->assertEquals($expected, $this->tournament->tally($scores));
24+
$this->assertEquals($expected, $tournament->tally($scores));
3125
}
3226

3327
/**
@@ -36,12 +30,13 @@ public function testJustTheHeaderIfNoInput(): void
3630
#[TestDox('A win is three points, a loss is zero points')]
3731
public function testAWinIsThreePointsALossIsZeroPoints(): void
3832
{
33+
$tournament = new Tournament();
3934
$scores = 'Allegoric Alaskans;Blithering Badgers;win';
4035
$expected =
4136
"Team | MP | W | D | L | P\n" .
4237
"Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" .
4338
"Blithering Badgers | 1 | 0 | 0 | 1 | 0";
44-
$this->assertEquals($expected, $this->tournament->tally($scores));
39+
$this->assertEquals($expected, $tournament->tally($scores));
4540
}
4641

4742
/**
@@ -50,12 +45,13 @@ public function testAWinIsThreePointsALossIsZeroPoints(): void
5045
#[TestDox('A win can also be expressed as a loss')]
5146
public function testAWinCanAlsoBeExpressedAsALoss(): void
5247
{
48+
$tournament = new Tournament();
5349
$scores = 'Blithering Badgers;Allegoric Alaskans;loss';
5450
$expected =
5551
"Team | MP | W | D | L | P\n" .
5652
"Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" .
5753
"Blithering Badgers | 1 | 0 | 0 | 1 | 0";
58-
$this->assertEquals($expected, $this->tournament->tally($scores));
54+
$this->assertEquals($expected, $tournament->tally($scores));
5955
}
6056

6157
/**
@@ -64,12 +60,13 @@ public function testAWinCanAlsoBeExpressedAsALoss(): void
6460
#[TestDox('A different team can win')]
6561
public function testADifferentTeamCanWin(): void
6662
{
63+
$tournament = new Tournament();
6764
$scores = 'Blithering Badgers;Allegoric Alaskans;win';
6865
$expected =
6966
"Team | MP | W | D | L | P\n" .
7067
"Blithering Badgers | 1 | 1 | 0 | 0 | 3\n" .
7168
"Allegoric Alaskans | 1 | 0 | 0 | 1 | 0";
72-
$this->assertEquals($expected, $this->tournament->tally($scores));
69+
$this->assertEquals($expected, $tournament->tally($scores));
7370
}
7471

7572
/**
@@ -78,12 +75,13 @@ public function testADifferentTeamCanWin(): void
7875
#[TestDox('A draw is one point each')]
7976
public function testADrawIsOnePointEach(): void
8077
{
78+
$tournament = new Tournament();
8179
$scores = 'Allegoric Alaskans;Blithering Badgers;draw';
8280
$expected =
8381
"Team | MP | W | D | L | P\n" .
8482
"Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n" .
8583
"Blithering Badgers | 1 | 0 | 1 | 0 | 1";
86-
$this->assertEquals($expected, $this->tournament->tally($scores));
84+
$this->assertEquals($expected, $tournament->tally($scores));
8785
}
8886

8987
/**
@@ -92,14 +90,15 @@ public function testADrawIsOnePointEach(): void
9290
#[TestDox('There can be more than one match')]
9391
public function testThereCanBeMoreThanOneMatch(): void
9492
{
93+
$tournament = new Tournament();
9594
$scores =
9695
"Allegoric Alaskans;Blithering Badgers;win\n" .
9796
"Allegoric Alaskans;Blithering Badgers;win";
9897
$expected =
9998
"Team | MP | W | D | L | P\n" .
10099
"Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" .
101100
"Blithering Badgers | 2 | 0 | 0 | 2 | 0";
102-
$this->assertEquals($expected, $this->tournament->tally($scores));
101+
$this->assertEquals($expected, $tournament->tally($scores));
103102
}
104103

105104
/**
@@ -108,14 +107,15 @@ public function testThereCanBeMoreThanOneMatch(): void
108107
#[TestDox('There can be more than one winner')]
109108
public function testThereCanBeMoreThanOneWinner(): void
110109
{
110+
$tournament = new Tournament();
111111
$scores =
112112
"Allegoric Alaskans;Blithering Badgers;loss\n" .
113113
"Allegoric Alaskans;Blithering Badgers;win";
114114
$expected =
115115
"Team | MP | W | D | L | P\n" .
116116
"Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n" .
117117
"Blithering Badgers | 2 | 1 | 0 | 1 | 3";
118-
$this->assertEquals($expected, $this->tournament->tally($scores));
118+
$this->assertEquals($expected, $tournament->tally($scores));
119119
}
120120

121121
/**
@@ -124,6 +124,7 @@ public function testThereCanBeMoreThanOneWinner(): void
124124
#[TestDox('There can be more than two teams')]
125125
public function testThereCanBeMoreThanTwoTeams(): void
126126
{
127+
$tournament = new Tournament();
127128
$scores =
128129
"Allegoric Alaskans;Blithering Badgers;win\n" .
129130
"Blithering Badgers;Courageous Californians;win\n" .
@@ -133,7 +134,7 @@ public function testThereCanBeMoreThanTwoTeams(): void
133134
"Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" .
134135
"Blithering Badgers | 2 | 1 | 0 | 1 | 3\n" .
135136
"Courageous Californians | 2 | 0 | 0 | 2 | 0";
136-
$this->assertEquals($expected, $this->tournament->tally($scores));
137+
$this->assertEquals($expected, $tournament->tally($scores));
137138
}
138139

139140
/**
@@ -142,6 +143,7 @@ public function testThereCanBeMoreThanTwoTeams(): void
142143
#[TestDox('Typical input')]
143144
public function testTypicalInput(): void
144145
{
146+
$tournament = new Tournament();
145147
$scores =
146148
"Allegoric Alaskans;Blithering Badgers;win\n" .
147149
"Devastating Donkeys;Courageous Californians;draw\n" .
@@ -155,7 +157,7 @@ public function testTypicalInput(): void
155157
"Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" .
156158
"Blithering Badgers | 3 | 1 | 0 | 2 | 3\n" .
157159
"Courageous Californians | 3 | 0 | 1 | 2 | 1";
158-
$this->assertEquals($expected, $this->tournament->tally($scores));
160+
$this->assertEquals($expected, $tournament->tally($scores));
159161
}
160162

161163
/**
@@ -164,6 +166,7 @@ public function testTypicalInput(): void
164166
#[TestDox('Incomplete competition (not all pairs have played)')]
165167
public function testIncompleteCompetitionNotAllPairsHavePlayed(): void
166168
{
169+
$tournament = new Tournament();
167170
$scores =
168171
"Allegoric Alaskans;Blithering Badgers;loss\n" .
169172
"Devastating Donkeys;Allegoric Alaskans;loss\n" .
@@ -175,7 +178,7 @@ public function testIncompleteCompetitionNotAllPairsHavePlayed(): void
175178
"Blithering Badgers | 2 | 1 | 1 | 0 | 4\n" .
176179
"Courageous Californians | 2 | 0 | 1 | 1 | 1\n" .
177180
"Devastating Donkeys | 1 | 0 | 0 | 1 | 0";
178-
$this->assertEquals($expected, $this->tournament->tally($scores));
181+
$this->assertEquals($expected, $tournament->tally($scores));
179182
}
180183

181184
/**
@@ -184,6 +187,7 @@ public function testIncompleteCompetitionNotAllPairsHavePlayed(): void
184187
#[TestDox('Ties broken alphabetically')]
185188
public function testTiesBrokenAlphabetically(): void
186189
{
190+
$tournament = new Tournament();
187191
$scores =
188192
"Courageous Californians;Devastating Donkeys;win\n" .
189193
"Allegoric Alaskans;Blithering Badgers;win\n" .
@@ -197,7 +201,7 @@ public function testTiesBrokenAlphabetically(): void
197201
"Courageous Californians | 3 | 2 | 1 | 0 | 7\n" .
198202
"Blithering Badgers | 3 | 0 | 1 | 2 | 1\n" .
199203
"Devastating Donkeys | 3 | 0 | 1 | 2 | 1";
200-
$this->assertEquals($expected, $this->tournament->tally($scores));
204+
$this->assertEquals($expected, $tournament->tally($scores));
201205
}
202206

203207
/**
@@ -206,6 +210,7 @@ public function testTiesBrokenAlphabetically(): void
206210
#[TestDox('Ensure points sorted numerically')]
207211
public function testEnsurePointsSortedNumerically(): void
208212
{
213+
$tournament = new Tournament();
209214
$scores =
210215
"Devastating Donkeys;Blithering Badgers;win\n" .
211216
"Devastating Donkeys;Blithering Badgers;win\n" .
@@ -216,6 +221,6 @@ public function testEnsurePointsSortedNumerically(): void
216221
"Team | MP | W | D | L | P\n" .
217222
"Devastating Donkeys | 5 | 4 | 0 | 1 | 12\n" .
218223
"Blithering Badgers | 5 | 1 | 0 | 4 | 3";
219-
$this->assertEquals($expected, $this->tournament->tally($scores));
224+
$this->assertEquals($expected, $tournament->tally($scores));
220225
}
221226
}

0 commit comments

Comments
 (0)