Skip to content

Commit d69f5ef

Browse files
committed
Bug fixes and additional tests.
1 parent b9ea471 commit d69f5ef

19 files changed

+129
-27
lines changed

src/main/java/lap_race/Input.java

+23
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,32 @@ private void loadEntry(final Team[] entries, final List<String> lines, final int
5858
if (team_elements.length != results.number_of_legs + 3)
5959
throw new RuntimeException("illegal composition for team: " + team_elements[0]);
6060

61+
final int bib_number = Integer.parseInt(team_elements[0]);
62+
final String team_name = team_elements[1];
63+
64+
if (entriesAlreadyContain(entries, bib_number))
65+
throw new RuntimeException("duplicate team number: " + bib_number);
66+
67+
if (entriesAlreadyContain(entries, team_name))
68+
throw new RuntimeException("duplicate team name: " + team_name);
69+
6170
entries[entry_index] = new Team(team_elements);
6271
}
6372

73+
private boolean entriesAlreadyContain(final Team[] entries, final int bib_number) {
74+
75+
for (Team team : entries)
76+
if (team != null && team.bib_number == bib_number) return true;
77+
return false;
78+
}
79+
80+
private boolean entriesAlreadyContain(final Team[] entries, final String team_name) {
81+
82+
for (Team team : entries)
83+
if (team != null && team.name.equals(team_name)) return true;
84+
return false;
85+
}
86+
6487
RawResult[] loadRawResults() throws IOException {
6588

6689
final List<String> lines = Files.readAllLines(raw_results_path);

src/main/java/lap_race/OutputCSV.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static void printLegResult(final OutputStreamWriter writer, final LegRes
150150
if (!leg_result.DNF) {
151151
writer.append(leg_result.position_string).append(",");
152152
writer.append(leg_result.team.runners[leg_result.leg_number - 1]).append(",");
153-
writer.append(format(leg_result.duration()));
153+
writer.append(format(leg_result.duration())).append("\n");
154154
}
155155
}
156156

src/main/java/lap_race/OutputHTML.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void printOverallResults(final OutputStreamWriter writer) throws IOExcep
8181
writer.append("""
8282
<tr>
8383
<td>""");
84-
writer.append(String.valueOf(position++));
84+
if (!result.dnf()) writer.append(String.valueOf(position++));
8585
writer.append("""
8686
</td>
8787
<td>""");
@@ -97,7 +97,7 @@ private void printOverallResults(final OutputStreamWriter writer) throws IOExcep
9797
writer.append("""
9898
</td>
9999
<td>""");
100-
writer.append(format(result.duration()));
100+
writer.append(result.dnf() ? DNF_STRING : format(result.duration()));
101101
writer.append("""
102102
</td>
103103
</tr>""");
@@ -222,8 +222,7 @@ private void printLegResultsHeader(final OutputStreamWriter writer, final int le
222222
<thead>
223223
<tr>
224224
<th>Pos</th>
225-
<th>Runner
226-
""");
225+
<th>Runner""");
227226

228227
if (results.paired_legs[leg-1]) writer.append("s");
229228

src/test/java/lap_race/devils_burdens/ResultsTest.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,39 @@ public void unregisteredTeam() throws Exception {
290290
configureTest("unregistered_team");
291291

292292
RuntimeException thrown = assertThrows(
293-
RuntimeException.class,
294-
() -> new Results(properties).processResults()
293+
RuntimeException.class,
294+
() -> new Results(properties).processResults()
295295
);
296296

297297
assertEquals("unregistered team: 4", thrown.getMessage());
298298
}
299299

300+
@Test
301+
public void duplicateTeamNumber() throws Exception {
302+
303+
configureTest("duplicate_team_number");
304+
305+
RuntimeException thrown = assertThrows(
306+
RuntimeException.class,
307+
() -> new Results(properties).processResults()
308+
);
309+
310+
assertEquals("duplicate team number: 3", thrown.getMessage());
311+
}
312+
313+
@Test
314+
public void duplicateTeamName() throws Exception {
315+
316+
configureTest("duplicate_team_name");
317+
318+
RuntimeException thrown = assertThrows(
319+
RuntimeException.class,
320+
() -> new Results(properties).processResults()
321+
);
322+
323+
assertEquals("duplicate team name: Team 2", thrown.getMessage());
324+
}
325+
300326
@Test
301327
public void extraResult() throws Exception {
302328

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1 Team 1 Women Senior John Smith Hailey Dickson:) & Alix Crawford Rhys Müllar & Paige Thompson Amé MacDonald
2+
2 Team 2 Open 50+ Bartosz Thomson John Smith & Zuzanna Miller-Ford Leo McKenzie & Henry Muir Regan Millar
3+
3 Team 2 Open Senior JackBruce Martin King & Leland Donaldson Neil MacDonald & Myles Christie Hubert Gray
4+
4 Team 4 Women 50+ Sofia O'Connor Philip O’Donohue & Hasan Robertson Lena K. Maclean & Isabel Ritchie Martha Gibson
5+
5 Team 5 Open Senior Clark O' Connor Nina Joan Fiona Walker & Hope Christie Cayla Duncan & Scott Kelly Amelia Muir

src/test/resources/devils_burdens/duplicate_team_name/input/rawtimes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 42:432 43:523 44:594 45:355 45:431 1:27:002 1:43:083 1:43:484 1:47:235 1:47:441 2:35:052 2:35:343 2:35:594 2:36:105 2:37:191 3:47:582 3:48:223 3:48:294 3:49:215 3:49:52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ENTRIES_FILENAME = entries.txt
2+
RAW_RESULTS_FILENAME = rawtimes.txt
3+
YEAR = 2020
4+
NUMBER_OF_LEGS = 4
5+
PAIRED_LEGS = 2,3
6+
RACE_NAME_FOR_RESULTS = Devil's Burdens
7+
RACE_NAME_FOR_FILENAMES = simple
8+
9+
# Elapsed duration from start of leg 1 to mass start time for each leg.
10+
# 23:59:59 indicates no mass start.
11+
MASS_START_ELAPSED_TIMES =
12+
13+
# Comma-separated sequence of bib-number/leg-number for all legs that have a time
14+
# recorded but the runners DNF'd the leg.
15+
DNF_LEGS =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 Team 1 Women Senior John Smith Hailey Dickson:) & Alix Crawford Rhys Müllar & Paige Thompson Amé MacDonald
2+
2 Team 2 Open 50+ Bartosz Thomson John Smith & Zuzanna Miller-Ford Leo McKenzie & Henry Muir Regan Millar
3+
3 Team 3 Open Senior JackBruce Martin King & Leland Donaldson Neil MacDonald & Myles Christie Hubert Gray
4+
3 Team 3b Open Senior JackBruce Martin King & Leland Donaldson Neil MacDonald & Myles Christie Hubert Gray
5+
4 Team 4 Open Senior JackBruce Martin King & Leland Donaldson Neil MacDonald & Myles Christie Hubert Gray
6+
5 Team 5 Open Senior Clark O' Connor Nina Joan Fiona Walker & Hope Christie Cayla Duncan & Scott Kelly Amelia Muir

src/test/resources/devils_burdens/duplicate_team_number/input/rawtimes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 42:432 43:523 44:594 45:355 45:431 1:27:002 1:43:083 1:43:484 1:47:235 1:47:441 2:35:052 2:35:343 2:35:594 2:36:105 2:37:191 3:47:582 3:48:223 3:48:294 3:49:215 3:49:52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ENTRIES_FILENAME = entries.txt
2+
RAW_RESULTS_FILENAME = rawtimes.txt
3+
YEAR = 2020
4+
NUMBER_OF_LEGS = 4
5+
PAIRED_LEGS = 2,3
6+
RACE_NAME_FOR_RESULTS = Devil's Burdens
7+
RACE_NAME_FOR_FILENAMES = simple
8+
9+
# Elapsed duration from start of leg 1 to mass start time for each leg.
10+
# 23:59:59 indicates no mass start.
11+
MASS_START_ELAPSED_TIMES =
12+
13+
# Comma-separated sequence of bib-number/leg-number for all legs that have a time
14+
# recorded but the runners DNF'd the leg.
15+
DNF_LEGS =

src/test/resources/devils_burdens/html_output/expected/simple_detailed_2020.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Pos,No,Team,Category,Runners 1,Leg 1,Split 1,Runners 2,Leg 2,Split 2,Runners 3,L
33
2,2,Team 2,Open 50+,Bartosz Thomson,00:43:52,00:43:52,John Smith & Zuzanna Miller-Ford,00:59:16,01:43:08,Leo McKenzie & Henry Muir,00:52:26,02:35:34,Regan Millar,01:12:48,03:48:22
44
3,3,Team 3,Open Senior,JackBruce,00:44:59,00:44:59,Martin King & Leland Donaldson,00:58:49,01:43:48,Neil MacDonald & Myles Christie,00:52:11,02:35:59,Hubert Gray,01:12:30,03:48:29
55
4,4,Team 4,Women 50+,Sofia O'Connor,00:45:35,00:45:35,Philip O’Donohue & Hasan Robertson,01:01:48,01:47:23,Lena K. Maclean & Isabel Ritchie,00:48:47,02:36:10,Martha Gibson,01:13:11,03:49:21
6-
5,5,Team 5,Open Senior,Clark O' Connor,00:45:43,00:45:43,Nina Joan Fiona Walker & Hope Christie,01:02:01,01:47:44,Cayla Duncan & Scott Kelly,00:49:35,02:37:19,Amelia Muir,01:12:33,03:49:52
6+
,5,Team 5,Open Senior,Clark O' Connor,00:45:43,00:45:43,Nina Joan Fiona Walker & Hope Christie,01:02:01,01:47:44,Cayla Duncan & Scott Kelly,00:49:35,02:37:19,Amelia Muir,DNF,DNF

src/test/resources/devils_burdens/html_output/expected/simple_detailed_2020.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<td>03:49:21</td>
9494
</tr>
9595
<tr>
96-
<td>5</td>
96+
<td></td>
9797
<td>5</td>
9898
<td>Team 5</td>
9999
<td>Open Senior</td>
@@ -107,8 +107,8 @@
107107
<td>00:49:35</td>
108108
<td>02:37:19</td>
109109
<td>Amelia Muir</td>
110-
<td>01:12:33</td>
111-
<td>03:49:52</td>
110+
<td>DNF</td>
111+
<td>DNF</td>
112112
</tr>
113113
</tbody>
114114
</table>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Pos,Runner,Time
22
1,Hubert Gray,01:12:30
3-
2,Amelia Muir,01:12:33
4-
3,Regan Millar,01:12:48
5-
4,Amé MacDonald,01:12:53
6-
5,Martha Gibson,01:13:11
3+
2,Regan Millar,01:12:48
4+
3,Amé MacDonald,01:12:53
5+
4,Martha Gibson,01:13:11

src/test/resources/devils_burdens/html_output/expected/simple_leg_4_2020.html

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@
1414
</tr>
1515
<tr>
1616
<td>2</td>
17-
<td>Amelia Muir</td>
18-
<td>01:12:33</td>
19-
</tr>
20-
<tr>
21-
<td>3</td>
2217
<td>Regan Millar</td>
2318
<td>01:12:48</td>
2419
</tr>
2520
<tr>
26-
<td>4</td>
21+
<td>3</td>
2722
<td>Amé MacDonald</td>
2823
<td>01:12:53</td>
2924
</tr>
3025
<tr>
31-
<td>5</td>
26+
<td>4</td>
3227
<td>Martha Gibson</td>
3328
<td>01:13:11</td>
3429
</tr>

src/test/resources/devils_burdens/html_output/expected/simple_overall_2020.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Pos,No,Team,Category,Total
33
2,2,Team 2,Open 50+,03:48:22
44
3,3,Team 3,Open Senior,03:48:29
55
4,4,Team 4,Women 50+,03:49:21
6-
5,5,Team 5,Open Senior,03:49:52
6+
,5,Team 5,Open Senior,DNF

src/test/resources/devils_burdens/html_output/expected/simple_overall_2020.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
<td>03:49:21</td>
3939
</tr>
4040
<tr>
41-
<td>5</td>
41+
<td></td>
4242
<td>5</td>
4343
<td>Team 5</td>
4444
<td>Open Senior</td>
45-
<td>03:49:52</td>
45+
<td>DNF</td>
4646
</tr>
4747
</tbody>
4848
</table>

src/test/resources/devils_burdens/html_output/expected/simple_prizes_2020.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Category: Open Senior
1212

1313
1: Team 1 (Women Senior) 03:47:58
1414
2: Team 3 (Open Senior) 03:48:29
15-
3: Team 5 (Open Senior) 03:49:52
1615

1716

1817
Category: Women 40+
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
1 42:432 43:523 44:594 45:355 45:431 1:27:002 1:43:083 1:43:484 1:47:235 1:47:441 2:35:052 2:35:343 2:35:594 2:36:105 2:37:191 3:47:582 3:48:223 3:48:294 3:49:215 3:49:52
1+
1 42:43
2+
2 43:52
3+
3 44:59
4+
4 45:35
5+
5 45:43
6+
1 1:27:00
7+
2 1:43:08
8+
3 1:43:48
9+
4 1:47:23
10+
5 1:47:44
11+
1 2:35:05
12+
2 2:35:34
13+
3 2:35:59
14+
4 2:36:10
15+
5 2:37:19
16+
1 3:47:58
17+
2 3:48:22
18+
3 3:48:29
19+
4 3:49:21
Binary file not shown.

0 commit comments

Comments
 (0)