Skip to content

Commit 492f208

Browse files
committed
MatrixTest, LuhnValidatorTest, PangramCheckerTest
1 parent 84c050c commit 492f208

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

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

Lines changed: 28 additions & 2 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;
@@ -13,138 +14,163 @@ 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
}
145168

146-
/* The following test diverges from the canonical test data. This is because the corresponding canonical test does
147-
* not account for Java specific functions (such as Character.getNumericValue()), which can be part of incorrect yet
169+
/*
170+
* The following test diverges from the canonical test data. This is because the
171+
* corresponding canonical test does
172+
* not account for Java specific functions (such as
173+
* Character.getNumericValue()), which can be part of incorrect yet
148174
* passing implementations. For more detail, check out issue #972 here:
149175
* (https://github.com/exercism/java/issues/972).
150176
*/

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
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;
12-
int[] expectedRow = {1};
14+
int[] expectedRow = { 1 };
1315

1416
Matrix matrix = new Matrix(matrixAsString);
1517

@@ -18,10 +20,11 @@ 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;
24-
int[] expectedRow = {3, 4};
27+
int[] expectedRow = { 3, 4 };
2528

2629
Matrix matrix = new Matrix(matrixAsString);
2730

@@ -30,10 +33,11 @@ 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;
36-
int[] expectedRow = {10, 20};
40+
int[] expectedRow = { 10, 20 };
3741

3842
Matrix matrix = new Matrix(matrixAsString);
3943

@@ -42,10 +46,11 @@ 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;
48-
int[] expectedRow = {8, 7, 6};
53+
int[] expectedRow = { 8, 7, 6 };
4954

5055
Matrix matrix = new Matrix(matrixAsString);
5156

@@ -54,10 +59,11 @@ 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;
60-
int[] expectedColumn = {1};
66+
int[] expectedColumn = { 1 };
6167

6268
Matrix matrix = new Matrix(matrixAsString);
6369

@@ -66,10 +72,11 @@ 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;
72-
int[] expectedColumn = {3, 6, 9};
79+
int[] expectedColumn = { 3, 6, 9 };
7380

7481
Matrix matrix = new Matrix(matrixAsString);
7582

@@ -78,10 +85,11 @@ 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;
84-
int[] expectedColumn = {4, 8, 6};
92+
int[] expectedColumn = { 4, 8, 6 };
8593

8694
Matrix matrix = new Matrix(matrixAsString);
8795

@@ -90,10 +98,11 @@ 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;
96-
int[] expectedColumn = {1903, 3, 4};
105+
int[] expectedColumn = { 1903, 3, 4 };
97106

98107
Matrix matrix = new Matrix(matrixAsString);
99108

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)