Skip to content

Commit 23eb65c

Browse files
authored
MatrixTest, LuhnValidatorTest, PangramCheckerTest (#3018)
* MatrixTest, LuhnValidatorTest, PangramCheckerTest * change * MatrixTest, LuhnValidatorTest, PangramCheckerTest * MatrixTest, LuhnValidatorTest, PangramCheckerTest * MatrixTest, LuhnValidatorTest, PangramCheckerTest [no important files changed]
1 parent 66f528b commit 23eb65c

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

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;

exercises/practice/pangram/src/test/java/PangramCheckerTest.java

Lines changed: 11 additions & 0 deletions
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;
@@ -14,60 +15,70 @@ public void setup() {
1415
}
1516

1617
@Test
18+
@DisplayName("empty sentence")
1719
public void emptySentenceIsNotPangram() {
1820
assertThat(pangramChecker.isPangram("")).isFalse();
1921
}
2022

2123
@Disabled("Remove to run test")
2224
@Test
25+
@DisplayName("perfect lower case")
2326
public void perfectLowerCasePhraseIsPangram() {
2427
assertThat(pangramChecker.isPangram("abcdefghijklmnopqrstuvwxyz")).isTrue();
2528
}
2629

2730
@Disabled("Remove to run test")
2831
@Test
32+
@DisplayName("only lower case")
2933
public void phraseWithOnlyLowerCaseIsPangram() {
3034
assertThat(pangramChecker.isPangram("the quick brown fox jumps over the lazy dog")).isTrue();
3135
}
3236

3337
@Disabled("Remove to run test")
3438
@Test
39+
@DisplayName("missing the letter 'x'")
3540
public void phraseMissingCharacterXIsNotPangram() {
3641
assertThat(pangramChecker.isPangram("a quick movement of the enemy will jeopardize five gunboats")).isFalse();
3742
}
3843

3944
@Disabled("Remove to run test")
4045
@Test
46+
@DisplayName("missing the letter 'h'")
4147
public void phraseMissingCharacterHIsNotPangram() {
4248
assertThat(pangramChecker.isPangram("five boxing wizards jump quickly at it")).isFalse();
4349
}
4450

4551
@Disabled("Remove to run test")
4652
@Test
53+
@DisplayName("with underscores")
4754
public void phraseWithUnderscoresIsPangram() {
4855
assertThat(pangramChecker.isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog")).isTrue();
4956
}
5057

5158
@Disabled("Remove to run test")
5259
@Test
60+
@DisplayName("with numbers")
5361
public void phraseWithNumbersIsPangram() {
5462
assertThat(pangramChecker.isPangram("the 1 quick brown fox jumps over the 2 lazy dogs")).isTrue();
5563
}
5664

5765
@Disabled("Remove to run test")
5866
@Test
67+
@DisplayName("missing letters replaced by numbers")
5968
public void phraseWithMissingLettersReplacedByNumbersIsNotPangram() {
6069
assertThat(pangramChecker.isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")).isFalse();
6170
}
6271

6372
@Disabled("Remove to run test")
6473
@Test
74+
@DisplayName("mixed case and punctuation")
6575
public void phraseWithMixedCaseAndPunctuationIsPangram() {
6676
assertThat(pangramChecker.isPangram("\"Five quacking Zephyrs jolt my wax bed.\"")).isTrue();
6777
}
6878

6979
@Disabled("Remove to run test")
7080
@Test
81+
@DisplayName("case insensitive")
7182
public void caseInsensitivePhraseIsNotPangram() {
7283
assertThat(pangramChecker.isPangram("abcdefghijklm ABCDEFGHIJKLM")).isFalse();
7384
}

0 commit comments

Comments
 (0)