Skip to content

Commit d5b13e9

Browse files
authored
Merge branch 'main' into add-rate-limiter-exercise
2 parents 0b158f7 + c2165cb commit d5b13e9

File tree

10 files changed

+178
-12
lines changed

10 files changed

+178
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ FootballMatchReports.onField(10);
2727
// => "striker"
2828
```
2929

30-
## 2. Raise an alert if an unknown shirt number is encountered
30+
## 2. Output "invalid" if the shirt number is not part of the official list
3131

32-
Modify the `FootballMatchReports.onField()` method to throw an `IllegalArgumentException` when a shirt number outside the range 1-11 is processed.
32+
Modify the `FootballMatchReports.onField()` method to return 'invalid' when a shirt number outside the range 1-11 is processed.
3333

3434
```java
3535
FootballMatchReports.onField(13);
36-
// => Throw IllegalArgumentException
36+
// => "invalid"
3737
```

exercises/concept/football-match-reports/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"Azumix"
44
],
5+
"contributors": [
6+
"AlvesJorge"
7+
],
58
"files": {
69
"solution": [
710
"src/main/java/FootballMatchReports.java"

exercises/concept/football-match-reports/.meta/src/reference/java/FootballMatchReports.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static String onField(int shirtNum) {
3030
playerDescription = "striker";
3131
break;
3232
default:
33-
throw new IllegalArgumentException();
33+
playerDescription = "invalid";
3434
}
3535
return playerDescription;
3636
}

exercises/concept/football-match-reports/src/test/java/FootballMatchReportsTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.junit.jupiter.api.Test;
44

55
import static org.assertj.core.api.Assertions.assertThat;
6-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
76

87
public class FootballMatchReportsTest {
98

@@ -68,17 +67,15 @@ public void test_right_wing() {
6867

6968
@Test
7069
@Tag("task:2")
71-
@DisplayName("The onField method throws IllegalArgumentException for unknown shirt number")
70+
@DisplayName("The onField method returns 'invalid' for invalid shirt number")
7271
public void test_exception() {
73-
assertThatExceptionOfType(IllegalArgumentException.class)
74-
.isThrownBy(() -> FootballMatchReports.onField(13));
72+
assertThat(FootballMatchReports.onField(13)).isEqualTo("invalid");
7573
}
7674

7775
@Test
7876
@Tag("task:2")
79-
@DisplayName("The onField method throws IllegalArgumentException for negative shirt number")
77+
@DisplayName("The onField method returns 'invalid' for negative shirt number")
8078
public void test_exception_negative_number() {
81-
assertThatExceptionOfType(IllegalArgumentException.class)
82-
.isThrownBy(() -> FootballMatchReports.onField(-1));
79+
assertThat(FootballMatchReports.onField(-1)).isEqualTo("invalid");
8380
}
8481
}

exercises/practice/luhn/src/test/java/LuhnValidatorTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.junit.jupiter.api.BeforeEach;
22
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.DisplayName;
34
import org.junit.jupiter.api.Test;
45

56
import static org.assertj.core.api.Assertions.assertThat;
@@ -13,132 +14,154 @@ public void setUp() {
1314
}
1415

1516
@Test
17+
@DisplayName("single digit strings can not be valid")
1618
public void testSingleDigitStringInvalid() {
1719
assertThat(luhnValidator.isValid("1")).isFalse();
1820
}
1921

2022
@Disabled("Remove to run test")
2123
@Test
24+
@DisplayName("a single zero is invalid")
2225
public void testSingleZeroIsInvalid() {
2326
assertThat(luhnValidator.isValid("0")).isFalse();
2427
}
2528

2629
@Disabled("Remove to run test")
2730
@Test
31+
@DisplayName("a simple valid SIN that remains valid if reversed")
2832
public void testSimpleValidSINReversedRemainsValid() {
2933
assertThat(luhnValidator.isValid("059")).isTrue();
3034
}
3135

3236
@Disabled("Remove to run test")
3337
@Test
38+
@DisplayName("a simple valid SIN that becomes invalid if reversed")
3439
public void testSimpleValidSINReversedBecomesInvalid() {
3540
assertThat(luhnValidator.isValid("59")).isTrue();
3641
}
3742

3843
@Disabled("Remove to run test")
3944
@Test
45+
@DisplayName("a valid Canadian SIN")
4046
public void testValidCanadianSINValid() {
4147
assertThat(luhnValidator.isValid("055 444 285")).isTrue();
4248
}
4349

4450
@Disabled("Remove to run test")
4551
@Test
52+
@DisplayName("invalid Canadian SIN")
4653
public void testInvalidCanadianSINInvalid() {
4754
assertThat(luhnValidator.isValid("055 444 286")).isFalse();
4855
}
4956

5057
@Disabled("Remove to run test")
5158
@Test
59+
@DisplayName("invalid credit card")
5260
public void testInvalidCreditCardInvalid() {
5361
assertThat(luhnValidator.isValid("8273 1232 7352 0569")).isFalse();
5462
}
5563

5664
@Disabled("Remove to run test")
5765
@Test
66+
@DisplayName("invalid long number with an even remainder")
5867
public void testInvalidLongNumberWithAnEvenRemainder() {
5968
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9012")).isFalse();
6069
}
6170

6271
@Disabled("Remove to run test")
6372
@Test
73+
@DisplayName("invalid long number with a remainder divisible by 5")
6474
public void testInvalidLongNumberWithARemainderDivisibleBy5() {
6575
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9013")).isFalse();
6676
}
6777

6878
@Disabled("Remove to run test")
6979
@Test
80+
@DisplayName("valid number with an even number of digits")
7081
public void testValidNumberWithAnEvenNumberOfDigits() {
7182
assertThat(luhnValidator.isValid("095 245 88")).isTrue();
7283
}
7384

7485
@Disabled("Remove to run test")
7586
@Test
87+
@DisplayName("valid number with an odd number of spaces")
7688
public void testValidNumberWithAnOddNumberOfSpaces() {
7789
assertThat(luhnValidator.isValid("234 567 891 234")).isTrue();
7890
}
7991

8092
@Disabled("Remove to run test")
8193
@Test
94+
@DisplayName("valid strings with a non-digit added at the end become invalid")
8295
public void testValidStringsWithANonDigitAtEndInvalid() {
8396
assertThat(luhnValidator.isValid("059a")).isFalse();
8497
}
8598

8699
@Disabled("Remove to run test")
87100
@Test
101+
@DisplayName("valid strings with punctuation included become invalid")
88102
public void testStringContainingPunctuationInvalid() {
89103
assertThat(luhnValidator.isValid("055-444-285")).isFalse();
90104
}
91105

92106
@Disabled("Remove to run test")
93107
@Test
108+
@DisplayName("valid strings with symbols included become invalid")
94109
public void testStringContainingSymbolsInvalid() {
95110
assertThat(luhnValidator.isValid("055# 444$ 285")).isFalse();
96111
}
97112

98113
@Disabled("Remove to run test")
99114
@Test
115+
@DisplayName("single zero with space is invalid")
100116
public void testSingleSpaceWithZeroInvalid() {
101117
assertThat(luhnValidator.isValid(" 0")).isFalse();
102118
}
103119

104120
@Disabled("Remove to run test")
105121
@Test
122+
@DisplayName("more than a single zero is valid")
106123
public void testMoreThanSingleZeroValid() {
107124
assertThat(luhnValidator.isValid("0000 0")).isTrue();
108125
}
109126

110127
@Disabled("Remove to run test")
111128
@Test
129+
@DisplayName("input digit 9 is correctly converted to output digit 9")
112130
public void testDigitNineConvertedToOutputNine() {
113131
assertThat(luhnValidator.isValid("091")).isTrue();
114132
}
115133

116134
@Disabled("Remove to run test")
117135
@Test
136+
@DisplayName("very long input is valid")
118137
public void testVeryLongInputIsValid() {
119138
assertThat(luhnValidator.isValid("9999999999 9999999999 9999999999 9999999999")).isTrue();
120139
}
121140

122141
@Disabled("Remove to run test")
123142
@Test
143+
@DisplayName("valid luhn with an odd number of digits and non zero first digit")
124144
public void testValidLuhnWithOddNumberOfDigitsAndNonZeroFirstDigit() {
125145
assertThat(luhnValidator.isValid("109")).isTrue();
126146
}
127147

128148
@Disabled("Remove to run test")
129149
@Test
150+
@DisplayName("using ascii value for non-doubled non-digit isn't allowed")
130151
public void testUsingASCIIValueForNonDoubledNonDigitNotAllowed() {
131152
assertThat(luhnValidator.isValid("055b 444 285")).isFalse();
132153
}
133154

134155
@Disabled("Remove to run test")
135156
@Test
157+
@DisplayName("using ascii value for doubled non-digit isn't allowed")
136158
public void testUsingASCIIValueForDoubledNonDigitNotAllowed() {
137159
assertThat(luhnValidator.isValid(":9")).isFalse();
138160
}
139161

140162
@Disabled("Remove to run test")
141163
@Test
164+
@DisplayName("non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed")
142165
public void testNonNumericNonSpaceCharInMiddleWithSumDivisibleBy10IsNotAllowed() {
143166
assertThat(luhnValidator.isValid("59%59")).isFalse();
144167
}
@@ -150,7 +173,8 @@ public void testNonNumericNonSpaceCharInMiddleWithSumDivisibleBy10IsNotAllowed()
150173
*/
151174
@Disabled("Remove to run test")
152175
@Test
153-
public void testStringContainingSymbolsInvalidJavaTrackSpecific() {
176+
@DisplayName("string containing symbols is invalid (Java track specific)")
177+
public void testStringContainingSymbolsIsInvalidJavaTrackSpecific() {
154178
assertThat(luhnValidator.isValid("85&")).isFalse();
155179
}
156180
}

exercises/practice/matrix/src/test/java/MatrixTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import static org.assertj.core.api.Assertions.assertThat;
56

67
public class MatrixTest {
78

89
@Test
10+
@DisplayName("extract row from one number matrix")
911
public void extractRowFromOneNumberMatrixTest() {
1012
String matrixAsString = "1";
1113
int rowIndex = 1;
@@ -18,6 +20,7 @@ public void extractRowFromOneNumberMatrixTest() {
1820

1921
@Disabled("Remove to run test")
2022
@Test
23+
@DisplayName("can extract row")
2124
public void extractRowFromMatrixTest() {
2225
String matrixAsString = "1 2\n3 4";
2326
int rowIndex = 2;
@@ -30,6 +33,7 @@ public void extractRowFromMatrixTest() {
3033

3134
@Disabled("Remove to run test")
3235
@Test
36+
@DisplayName("extract row where numbers have different widths")
3337
public void extractRowFromDiffWidthsMatrixTest() {
3438
String matrixAsString = "1 2\n10 20";
3539
int rowIndex = 2;
@@ -42,6 +46,7 @@ public void extractRowFromDiffWidthsMatrixTest() {
4246

4347
@Disabled("Remove to run test")
4448
@Test
49+
@DisplayName("can extract row from non-square matrix with no corresponding column")
4550
public void extractRowFromNonSquareMatrixTest() {
4651
String matrixAsString = "1 2 3\n4 5 6\n7 8 9\n8 7 6";
4752
int rowIndex = 4;
@@ -54,6 +59,7 @@ public void extractRowFromNonSquareMatrixTest() {
5459

5560
@Disabled("Remove to run test")
5661
@Test
62+
@DisplayName("extract column from one number matrix")
5763
public void extractColumnFromOneNumberMatrixTest() {
5864
String matrixAsString = "1";
5965
int columnIndex = 1;
@@ -66,6 +72,7 @@ public void extractColumnFromOneNumberMatrixTest() {
6672

6773
@Disabled("Remove to run test")
6874
@Test
75+
@DisplayName("can extract column")
6976
public void extractColumnMatrixTest() {
7077
String matrixAsString = "1 2 3\n4 5 6\n7 8 9";
7178
int columnIndex = 3;
@@ -78,6 +85,7 @@ public void extractColumnMatrixTest() {
7885

7986
@Disabled("Remove to run test")
8087
@Test
88+
@DisplayName("can extract column from non-square matrix with no corresponding row")
8189
public void extractColumnFromNonSquareMatrixTest() {
8290
String matrixAsString = "1 2 3 4\n5 6 7 8\n9 8 7 6";
8391
int columnIndex = 4;
@@ -90,6 +98,7 @@ public void extractColumnFromNonSquareMatrixTest() {
9098

9199
@Disabled("Remove to run test")
92100
@Test
101+
@DisplayName("extract column where numbers have different widths")
93102
public void extractColumnFromDiffWidthsMatrixTest() {
94103
String matrixAsString = "89 1903 3\n18 3 1\n9 4 800";
95104
int columnIndex = 2;

0 commit comments

Comments
 (0)