Skip to content

Commit 6397978

Browse files
authored
fix: remove exceptions from football match reports (#2322)
1 parent 2993124 commit 6397978

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

exercises/concept/football-match-reports/.docs/hints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- The [`break`][break] statement is useful.
88

9-
## 2. Raise an alert if an unknown shirt number is encountered
9+
## 2. Handle unknown shirt numbers
1010

1111
- The [`default`][default] statement is useful.
1212

exercises/concept/football-match-reports/.docs/instructions.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
You are developing a system to help the staff of a football/soccer club's web site report on matches.
3+
You are developing a system to help the staff of a football/soccer club's web site report on matches.
44
This system is capable of analyzing different aspects in the match, both on and off the field, and converts them into a stream of events.
55

66
## 1. Output descriptions of the players based on their shirt number
@@ -9,7 +9,7 @@ The team only ever plays a 4-3-3 formation and has never agreed with the 1965 ch
99

1010
The player descriptions are as follows:
1111

12-
```
12+
```text
1313
1 -> "goalie"
1414
2 -> "left back"
1515
3 & 4 -> "center back"
@@ -27,9 +27,9 @@ PlayAnalyzer.AnalyzeOnField(10);
2727
// => "striker"
2828
```
2929

30-
## 2. Raise an alert if an unknown shirt number is encountered
30+
## 2. Handle unknown shirt numbers
3131

32-
Modify the `PlayAnalyzer.AnalyzeOnField()` method to throw an `ArgumentOutOfRangeException` when a shirt number outside the range 1-11 is processed.
32+
Modify the `PlayAnalyzer.AnalyzeOnField()` method to report `UNKNOWN` when a shirt number outside the range 1-11 is processed.
3333

3434
## 3. Extend the coverage to include off field activity
3535

@@ -41,7 +41,7 @@ To start off, we will cover data about the stadium:
4141
- The current number of supporters in the stadium (any `int`)
4242
- Announcements made over the stadium's PA system (any `string`)
4343

44-
Unknown types of data should not be processed, so if the method receives data of a different type an `ArgumentException` should be thrown.
44+
Unknown types of data should not be processed, so if the method receives data of a different type an empty string should be returned.
4545

4646
```csharp
4747
PlayAnalyzer.AnalyzeOffField(5000);
@@ -51,15 +51,15 @@ PlayAnalyzer.AnalyzeOffField("5 minutes to go!");
5151
// => "5 minutes to go!"
5252
5353
PlayAnalyzer.AnalyzeOffField(0.5);
54-
// => throws ArgumentException
54+
// => ""
5555
```
5656

5757
## 4. Report on incidents during the match
5858

59-
Modify the `PlayAnalyzer.AnalyzeOffField()` method to output descriptions of incidents that happen during the match.
59+
Modify the `PlayAnalyzer.AnalyzeOffField()` method to output descriptions of incidents that happen during the match.
6060

61-
Incidents can be any subclass of the `Incident` type, and will contain a description of the incident.
62-
Injuries are a special kind of incident because they cause the match to be put on hold, so they should be treated differently.
61+
Incidents can be any subclass of the `Incident` type, and will contain a description of the incident.
62+
Injuries are a special kind of incident because they cause the match to be put on hold, so they should be treated differently.
6363

6464
```csharp
6565
PlayAnalyzer.AnalyzeOffField(new Foul());
@@ -73,8 +73,8 @@ PlayAnalyzer.AnalyzeOffField(new Injury(8));
7373

7474
Modify the `PlayAnalyzer.AnalyzeOffField()` method to mention the club managers present during the match.
7575

76-
Managers are instances of the `Manager` type and have a name and the name of the club they manage.
77-
The manager's club may be unknown, in which case it will be set to `null`.
76+
Managers are instances of the `Manager` type and have a name and the name of the club they manage.
77+
The manager's club may be unknown, in which case it will be set to `null`.
7878
If a manager's club is not known, it should not be part of the description.
7979

8080
```csharp

exercises/concept/football-match-reports/.meta/Exemplar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static string AnalyzeOnField(int shirtNum)
2626
case 10:
2727
return "striker";
2828
default:
29-
throw new ArgumentOutOfRangeException();
29+
return "UNKNOWN";
3030
}
3131
}
3232

@@ -47,7 +47,7 @@ public static string AnalyzeOffField(object report)
4747
case Manager manager:
4848
return manager.Name;
4949
default:
50-
throw new ArgumentException();
50+
return "";
5151
}
5252
}
5353
}

exercises/concept/football-match-reports/.meta/design.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- switch expressions
1212
- pattern matching tuples
1313
- enums
14+
- exceptions
1415

1516
## Concepts
1617

exercises/concept/football-match-reports/FootballMatchReportsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public void AnalyzeOnField_11()
3434

3535
[Fact]
3636
[Task(2)]
37-
public void AnalyzeOnField_throws_unknown_shirt_number()
37+
public void AnalyzeOnField_with_unknown_shirt_number()
3838
{
39-
Assert.Throws<ArgumentOutOfRangeException>(() => PlayAnalyzer.AnalyzeOnField(1729));
39+
Assert.Equal("UNKNOWN", PlayAnalyzer.AnalyzeOnField(1729));
4040
}
4141

4242
[Fact]
@@ -50,7 +50,7 @@ public void AnalyzeOffField_number()
5050
[Task(3)]
5151
public void AnalyzeOffField_throws_unknown_type()
5252
{
53-
Assert.Throws<ArgumentException>(() => PlayAnalyzer.AnalyzeOffField(90.0f));
53+
Assert.Equal("", PlayAnalyzer.AnalyzeOffField(90.0f));
5454
}
5555

5656
[Fact]

0 commit comments

Comments
 (0)