@@ -21,10 +21,10 @@ class AwardServiceTest extends KernelTestCase
21
21
22
22
protected function setUp (): void
23
23
{
24
- // The contest will have 1 gold, 1 silver and 2 bronze medals
24
+ // The contest will have 2 gold, 2 silver and 2 bronze medals, awarded only to category A and C
25
25
$ this ->contest = (new Contest ())
26
26
->setMedalsEnabled (true )
27
- ->setGoldMedals (1 )
27
+ ->setGoldMedals (2 )
28
28
->setSilverMedals (1 )
29
29
->setBronzeMedals (1 );
30
30
$ categoryA = (new TeamCategory ())
@@ -33,22 +33,33 @@ protected function setUp(): void
33
33
$ categoryB = (new TeamCategory ())
34
34
->setName ('Category B ' )
35
35
->setExternalid ('cat_B ' );
36
+ $ categoryC = (new TeamCategory ())
37
+ ->setName ('Category C ' )
38
+ ->setExternalid ('cat_C ' );
36
39
$ this ->contest
37
40
->addMedalCategory ($ categoryA )
38
- ->addMedalCategory ($ categoryB );
41
+ ->addMedalCategory ($ categoryC );
39
42
$ reflectedProblem = new ReflectionClass (TeamCategory::class);
40
- $ teamIdProperty = $ reflectedProblem ->getProperty ('categoryid ' );
41
- $ teamIdProperty ->setAccessible (true );
42
- $ teamIdProperty ->setValue ($ categoryA , 1 );
43
- $ teamIdProperty ->setValue ($ categoryB , 2 );
43
+ $ categoryIdProperty = $ reflectedProblem ->getProperty ('categoryid ' );
44
+ $ categoryIdProperty ->setAccessible (true );
45
+ $ categoryIdProperty ->setValue ($ categoryA , 1 );
46
+ $ categoryIdProperty ->setValue ($ categoryB , 2 );
47
+ $ categoryIdProperty ->setValue ($ categoryC , 3 );
44
48
$ categories = [$ categoryA , $ categoryB ];
45
- // Create 4 teams, each belonging to a category
49
+ // Create 9 teams, each belonging to a different category
46
50
$ teams = [];
47
- foreach (['A ' , 'B ' , 'C ' , 'D ' ] as $ teamLetter ) {
51
+ foreach (['A ' , 'B ' , 'C ' , 'D ' , 'E ' , 'F ' , 'G ' , 'H ' , 'I ' ] as $ teamLetter ) {
52
+ $ category = $ categoryC ;
53
+ if (in_array ($ teamLetter , ['A ' , 'B ' , 'C ' ])) {
54
+ $ category = $ categoryA ;
55
+ }
56
+ if (in_array ($ teamLetter , ['D ' , 'E ' , 'F ' ])) {
57
+ $ category = $ categoryB ;
58
+ }
48
59
$ team = (new Team ())
49
60
->setName ('Team ' . $ teamLetter )
50
61
->setExternalid ('team_ ' . $ teamLetter )
51
- ->setCategory (in_array ( $ teamLetter , [ ' A ' , ' B ' ]) ? $ categoryA : $ categoryB )
62
+ ->setCategory ($ category )
52
63
->setAffiliation (); // No affiliation needed
53
64
$ reflectedProblem = new ReflectionClass (Team::class);
54
65
$ teamIdProperty = $ reflectedProblem ->getProperty ('teamid ' );
@@ -81,16 +92,25 @@ protected function setUp(): void
81
92
// -----+-----------
82
93
// A | 1 5 10 20
83
94
// B | x 2 3 x
84
- // C | x x x 4
85
- // D | x x x x
95
+ // C | x 2 3 x
96
+ // D | x x x 12
97
+ // E | x x x 13
98
+ // F | x x x 14
99
+ // G | x x x 15
100
+ // H | x x x x
101
+ // I | x x x x
86
102
//
87
103
// THis means A is the overall winner, will get a gold medal and is the winner
88
104
// of category A. It is also first to solve problem A.
89
- // B is second, so it gets a silver medal. It is also first to solve problem B and C
90
- // C is the first to solve problem D, gets a bronze medal and is winner of category B.
91
- // D didn't solve anything, so it will not get any medals at all
105
+ // B is second, so it also gets a gold medal. It is also first to solve problem B and C
106
+ // C scored the exact same as B, so it also gets the same medals
107
+ // D is the first to solve problem D and is the winner of category B. But will not get any medal.
108
+ // E and F will get no awards at all.
109
+ // G is the winner of category C and will get a bronze medal.
110
+ // The reason G doesn't get silver is that C would get silver if it was ranked differently,
111
+ // but it is not.
112
+ // H and I didn't solve anything, so it will not get any medals at all
92
113
93
- $ minute = 60 ;
94
114
// Indexed first by team, then by problem
95
115
$ scores = [
96
116
'A ' => [
@@ -104,15 +124,28 @@ protected function setUp(): void
104
124
'C ' => 3 ,
105
125
],
106
126
'C ' => [
107
- 'D ' => 4 ,
127
+ 'B ' => 2 ,
128
+ 'C ' => 3 ,
129
+ ],
130
+ 'D ' => [
131
+ 'D ' => 12 ,
132
+ ],
133
+ 'E ' => [
134
+ 'D ' => 13 ,
135
+ ],
136
+ 'F ' => [
137
+ 'D ' => 14 ,
138
+ ],
139
+ 'G ' => [
140
+ 'D ' => 15 ,
108
141
],
109
142
];
110
143
$ scoreCache = [];
111
144
foreach ($ scores as $ teamLabel => $ scoresForTeam ) {
112
145
foreach ($ scoresForTeam as $ problemLabel => $ minute ) {
113
146
$ firstToSolve = in_array (
114
147
$ teamLabel . $ problemLabel ,
115
- ['AA ' , 'BB ' , 'BC ' , 'CD ' ]
148
+ ['AA ' , 'BB ' , 'BC ' , 'CB ' , ' CC ' , ' DD ' ]
116
149
);
117
150
$ scoreCache [] = (new ScoreCache ())
118
151
->setContest ($ this ->contest )
@@ -164,15 +197,19 @@ public function testWinner(): void
164
197
public function testMedals (): void
165
198
{
166
199
$ medals = [
167
- 'gold ' => 'team_A ' ,
168
- 'silver ' => ' team_B ' ,
169
- 'bronze ' => ' team_C ' ,
200
+ 'gold ' => [ 'team_A ' , ' team_B ' , ' team_C ' ] ,
201
+ 'silver ' => [] ,
202
+ 'bronze ' => [ ' team_G ' ] ,
170
203
];
171
- foreach ($ medals as $ medal => $ team ) {
204
+ foreach ($ medals as $ medal => $ teams ) {
172
205
$ medalAward = $ this ->getAward ($ medal . '-medal ' );
173
- static ::assertNotNull ($ medalAward );
174
- static ::assertEquals (ucfirst ($ medal ) . ' medal winner ' , $ medalAward ['citation ' ]);
175
- static ::assertEquals ([$ team ], $ medalAward ['team_ids ' ]);
206
+ if (empty ($ teams )) {
207
+ static ::assertNull ($ medalAward );
208
+ } else {
209
+ static ::assertNotNull ($ medalAward );
210
+ static ::assertEquals (ucfirst ($ medal ) . ' medal winner ' , $ medalAward ['citation ' ]);
211
+ static ::assertEquals ($ teams , $ medalAward ['team_ids ' ]);
212
+ }
176
213
}
177
214
}
178
215
@@ -187,22 +224,29 @@ public function testGroupWinners(): void
187
224
$ groupBWinner = $ this ->getAward ('group-winner-cat_B ' );
188
225
static ::assertNotNull ($ groupBWinner );
189
226
static ::assertEquals ('Winner(s) of group Category B ' , $ groupBWinner ['citation ' ]);
190
- static ::assertEquals (['team_C ' ], $ groupBWinner ['team_ids ' ]);
227
+ static ::assertEquals (['team_D ' ], $ groupBWinner ['team_ids ' ]);
228
+
229
+ $ a = $ this ->getAwardService ()->getAwards ($ this ->contest , $ this ->scoreboard );
230
+ $ groupBWinner = $ this ->getAward ('group-winner-cat_C ' );
231
+ static ::assertNotNull ($ groupBWinner );
232
+ static ::assertEquals ('Winner(s) of group Category C ' , $ groupBWinner ['citation ' ]);
233
+ static ::assertEquals (['team_G ' ], $ groupBWinner ['team_ids ' ]);
191
234
}
192
235
193
236
public function testFirstToSolve (): void
194
237
{
195
238
$ fts = [
196
- 'A ' => 'A ' ,
197
- 'B ' => 'B ' ,
198
- 'C ' => 'B ' ,
199
- 'D ' => ' C ' ,
239
+ 'A ' => [ 'A ' ] ,
240
+ 'B ' => [ 'B ' , ' C ' ] ,
241
+ 'C ' => [ 'B ' , ' C ' ] ,
242
+ 'D ' => [ ' D ' ] ,
200
243
];
201
- foreach ($ fts as $ problem => $ team ) {
244
+ foreach ($ fts as $ problem => $ teams ) {
202
245
$ firstToSolve = $ this ->getAward ('first-to-solve-problem_ ' . $ problem );
203
246
static ::assertNotNull ($ firstToSolve );
204
247
static ::assertEquals ('First to solve problem ' . $ problem , $ firstToSolve ['citation ' ]);
205
- static ::assertEquals (['team_ ' . $ team ], $ firstToSolve ['team_ids ' ]);
248
+ $ teamIds = array_map (static fn (string $ team ) => 'team_ ' . $ team , $ teams );
249
+ static ::assertEquals ($ teamIds , $ firstToSolve ['team_ids ' ]);
206
250
}
207
251
}
208
252
@@ -219,8 +263,13 @@ public function testMedalType(int $teamIndex, ?string $expectedMedalType)
219
263
public function provideMedalType (): \Generator
220
264
{
221
265
yield [0 , 'gold-medal ' ];
222
- yield [1 , 'silver -medal ' ];
223
- yield [2 , 'bronze -medal ' ];
266
+ yield [1 , 'gold -medal ' ];
267
+ yield [2 , 'gold -medal ' ];
224
268
yield [3 , null ];
269
+ yield [4 , null ];
270
+ yield [5 , null ];
271
+ yield [6 , 'bronze-medal ' ];
272
+ yield [7 , null ];
273
+ yield [8 , null ];
225
274
}
226
275
}
0 commit comments