Skip to content

Commit 7fb1db8

Browse files
authored
nth-prime, nucleotide-count, ocr-numbers, palindrome-products (#3024)
* nth-prime, nucleotide-count, ocr-numbers, palindrome-products * Update PrimeCalculatorTest.java [no important files changed]
1 parent 86a5d7c commit 7fb1db8

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

exercises/practice/nth-prime/src/test/java/PrimeCalculatorTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
import static org.assertj.core.api.Assertions.assertThat;
22
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33

4-
54
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.DisplayName;
66
import org.junit.jupiter.api.Test;
77

88
public class PrimeCalculatorTest {
99

1010
private PrimeCalculator primeCalculator = new PrimeCalculator();
1111

1212
@Test
13+
@DisplayName("first prime")
1314
public void testFirstPrime() {
1415
assertThat(primeCalculator.nth(1)).isEqualTo(2);
1516
}
1617

1718
@Disabled("Remove to run test")
1819
@Test
20+
@DisplayName("second prime")
1921
public void testSecondPrime() {
2022
assertThat(primeCalculator.nth(2)).isEqualTo(3);
2123
}
2224

2325
@Disabled("Remove to run test")
2426
@Test
27+
@DisplayName("sixth prime")
2528
public void testSixthPrime() {
2629
assertThat(primeCalculator.nth(6)).isEqualTo(13);
2730
}
2831

2932
@Disabled("Remove to run test")
3033
@Test
34+
@DisplayName("big prime")
3135
public void testBigPrime() {
3236
assertThat(primeCalculator.nth(10001)).isEqualTo(104743);
3337
}
3438

3539
@Disabled("Remove to run test")
3640
@Test
41+
@DisplayName("there is no zeroth prime")
3742
public void testUndefinedPrime() {
3843
assertThatExceptionOfType(IllegalArgumentException.class)
3944
.isThrownBy(() -> primeCalculator.nth(0));

exercises/practice/nucleotide-count/src/test/java/NucleotideCounterTest.java

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

45
import java.util.Map;
@@ -9,6 +10,7 @@
910
public class NucleotideCounterTest {
1011

1112
@Test
13+
@DisplayName("empty strand")
1214
public void testEmptyDnaStringHasNoNucleotides() {
1315
NucleotideCounter nucleotideCounter = new NucleotideCounter("");
1416

@@ -19,6 +21,7 @@ public void testEmptyDnaStringHasNoNucleotides() {
1921

2022
@Disabled("Remove to run test")
2123
@Test
24+
@DisplayName("can count one nucleotide in single-character input")
2225
public void testDnaStringHasOneNucleotide() {
2326
NucleotideCounter nucleotideCounter = new NucleotideCounter("G");
2427

@@ -29,6 +32,7 @@ public void testDnaStringHasOneNucleotide() {
2932

3033
@Disabled("Remove to run test")
3134
@Test
35+
@DisplayName("strand with repeated nucleotide")
3236
public void testRepetitiveSequenceWithOnlyGuanine() {
3337
NucleotideCounter nucleotideCounter = new NucleotideCounter("GGGGGGG");
3438

@@ -39,6 +43,7 @@ public void testRepetitiveSequenceWithOnlyGuanine() {
3943

4044
@Disabled("Remove to run test")
4145
@Test
46+
@DisplayName("strand with multiple nucleotides")
4247
public void testDnaStringHasMultipleNucleotide() {
4348
NucleotideCounter nucleotideCounter
4449
= new NucleotideCounter("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
@@ -50,6 +55,7 @@ public void testDnaStringHasMultipleNucleotide() {
5055

5156
@Disabled("Remove to run test")
5257
@Test
58+
@DisplayName("strand with invalid nucleotides")
5359
public void testDnaStringHasInvalidNucleotides() {
5460
assertThatThrownBy(() -> new NucleotideCounter("AGXXACT"))
5561
.isInstanceOf(IllegalArgumentException.class);

exercises/practice/ocr-numbers/src/test/java/OpticalCharacterReaderTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33

44
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.DisplayName;
56
import org.junit.jupiter.api.Test;
67

78
import java.util.Arrays;
89

910
public class OpticalCharacterReaderTest {
1011

1112
@Test
13+
@DisplayName("Recognizes 0")
1214
public void testReaderRecognizesSingle0() {
1315
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
1416
" _ ",
@@ -23,6 +25,7 @@ public void testReaderRecognizesSingle0() {
2325

2426
@Disabled("Remove to run test")
2527
@Test
28+
@DisplayName("Recognizes 1")
2629
public void testReaderRecognizesSingle1() {
2730
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
2831
" ",
@@ -36,6 +39,7 @@ public void testReaderRecognizesSingle1() {
3639

3740
@Disabled("Remove to run test")
3841
@Test
42+
@DisplayName("Unreadable but correctly sized inputs return ?")
3943
public void testReaderReturnsQuestionMarkForUnreadableButCorrectlySizedInput() {
4044
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
4145
" ",
@@ -49,6 +53,7 @@ public void testReaderReturnsQuestionMarkForUnreadableButCorrectlySizedInput() {
4953

5054
@Disabled("Remove to run test")
5155
@Test
56+
@DisplayName("Input with a number of lines that is not a multiple of four raises an error")
5257
public void testReaderThrowsExceptionWhenNumberOfInputLinesIsNotAMultipleOf4() {
5358

5459
assertThatExceptionOfType(IllegalArgumentException.class)
@@ -63,6 +68,7 @@ public void testReaderThrowsExceptionWhenNumberOfInputLinesIsNotAMultipleOf4() {
6368

6469
@Disabled("Remove to run test")
6570
@Test
71+
@DisplayName("Input with a number of columns that is not a multiple of three raises an error")
6672
public void testReaderThrowsExceptionWhenNumberOfInputColumnsIsNotAMultipleOf3() {
6773

6874

@@ -79,6 +85,7 @@ public void testReaderThrowsExceptionWhenNumberOfInputColumnsIsNotAMultipleOf3()
7985

8086
@Disabled("Remove to run test")
8187
@Test
88+
@DisplayName("Recognizes 110101100")
8289
public void testReaderRecognizesBinarySequence110101100() {
8390
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
8491
" _ _ _ _ ",
@@ -92,6 +99,7 @@ public void testReaderRecognizesBinarySequence110101100() {
9299

93100
@Disabled("Remove to run test")
94101
@Test
102+
@DisplayName("Garbled numbers in a string are replaced with ?")
95103
public void testReaderReplacesUnreadableDigitsWithQuestionMarksWithinSequence() {
96104
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
97105
" _ _ _ ",
@@ -106,6 +114,7 @@ public void testReaderReplacesUnreadableDigitsWithQuestionMarksWithinSequence()
106114

107115
@Disabled("Remove to run test")
108116
@Test
117+
@DisplayName("Recognizes 2")
109118
public void testReaderRecognizesSingle2() {
110119
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
111120
" _ ",
@@ -119,6 +128,7 @@ public void testReaderRecognizesSingle2() {
119128

120129
@Disabled("Remove to run test")
121130
@Test
131+
@DisplayName("Recognizes 3")
122132
public void testReaderRecognizesSingle3() {
123133
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
124134
" _ ",
@@ -132,6 +142,7 @@ public void testReaderRecognizesSingle3() {
132142

133143
@Disabled("Remove to run test")
134144
@Test
145+
@DisplayName("Recognizes 4")
135146
public void testReaderRecognizesSingle4() {
136147
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
137148
" ",
@@ -145,6 +156,7 @@ public void testReaderRecognizesSingle4() {
145156

146157
@Disabled("Remove to run test")
147158
@Test
159+
@DisplayName("Recognizes 5")
148160
public void testReaderRecognizesSingle5() {
149161
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
150162
" _ ",
@@ -158,6 +170,7 @@ public void testReaderRecognizesSingle5() {
158170

159171
@Disabled("Remove to run test")
160172
@Test
173+
@DisplayName("Recognizes 6")
161174
public void testReaderRecognizesSingle6() {
162175
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
163176
" _ ",
@@ -171,6 +184,7 @@ public void testReaderRecognizesSingle6() {
171184

172185
@Disabled("Remove to run test")
173186
@Test
187+
@DisplayName("Recognizes 7")
174188
public void testReaderRecognizesSingle7() {
175189
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
176190
" _ ",
@@ -184,6 +198,7 @@ public void testReaderRecognizesSingle7() {
184198

185199
@Disabled("Remove to run test")
186200
@Test
201+
@DisplayName("Recognizes 8")
187202
public void testReaderRecognizesSingle8() {
188203
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
189204
" _ ",
@@ -197,6 +212,7 @@ public void testReaderRecognizesSingle8() {
197212

198213
@Disabled("Remove to run test")
199214
@Test
215+
@DisplayName("Recognizes 9")
200216
public void testReaderRecognizesSingle9() {
201217
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
202218
" _ ",
@@ -210,6 +226,7 @@ public void testReaderRecognizesSingle9() {
210226

211227
@Disabled("Remove to run test")
212228
@Test
229+
@DisplayName("Recognizes string of decimal numbers")
213230
public void testReaderRecognizesSequence1234567890() {
214231
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
215232
" _ _ _ _ _ _ _ _ ",
@@ -223,6 +240,7 @@ public void testReaderRecognizesSequence1234567890() {
223240

224241
@Disabled("Remove to run test")
225242
@Test
243+
@DisplayName("Numbers separated by empty lines are recognized. Lines are joined by commas.")
226244
public void testReaderRecognizesAndCorrectlyFormatsMultiRowInput() {
227245
String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
228246
" _ _ ",

exercises/practice/palindrome-products/src/test/java/PalindromeCalculatorTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33

44
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.DisplayName;
56
import org.junit.jupiter.api.Test;
67

78
import java.util.Arrays;
@@ -15,6 +16,7 @@ public class PalindromeCalculatorTest {
1516
private PalindromeCalculator palindromeCalculator = new PalindromeCalculator();
1617

1718
@Test
19+
@DisplayName("find the smallest palindrome from single digit factors")
1820
public void smallestPalindromeFromSingleDigitFactors() {
1921
List<List<Integer>> expected = Collections.unmodifiableList(
2022
Arrays.asList(
@@ -30,6 +32,7 @@ public void smallestPalindromeFromSingleDigitFactors() {
3032

3133
@Disabled("Remove to run test")
3234
@Test
35+
@DisplayName("find the largest palindrome from single digit factors")
3336
public void largestPalindromeFromSingleDigitFactors() {
3437
List<List<Integer>> expected = Collections.unmodifiableList(
3538
Arrays.asList(
@@ -46,6 +49,7 @@ public void largestPalindromeFromSingleDigitFactors() {
4649

4750
@Disabled("Remove to run test")
4851
@Test
52+
@DisplayName("find the smallest palindrome from double digit factors")
4953
public void largestPalindromeFromDoubleDigitFactors() {
5054
List<List<Integer>> expected = Collections.unmodifiableList(
5155
Arrays.asList(
@@ -62,6 +66,7 @@ public void largestPalindromeFromDoubleDigitFactors() {
6266

6367
@Disabled("Remove to run test")
6468
@Test
69+
@DisplayName("find the largest palindrome from double digit factors")
6570
public void smallestPalindromeFromDoubleDigitFactors() {
6671
List<List<Integer>> expected = Collections.unmodifiableList(
6772
Arrays.asList(
@@ -78,6 +83,7 @@ public void smallestPalindromeFromDoubleDigitFactors() {
7883

7984
@Disabled("Remove to run test")
8085
@Test
86+
@DisplayName("find the largest palindrome from triple digit factors")
8187
public void largestPalindromeFromTripleDigitFactors() {
8288
List<List<Integer>> expected = Collections.unmodifiableList(
8389
Arrays.asList(
@@ -94,6 +100,7 @@ public void largestPalindromeFromTripleDigitFactors() {
94100

95101
@Disabled("Remove to run test")
96102
@Test
103+
@DisplayName("find the smallest palindrome from triple digit factors")
97104
public void smallestPalindromeFromTripleDigitFactors() {
98105
List<List<Integer>> expected = Collections.unmodifiableList(
99106
Arrays.asList(
@@ -110,6 +117,7 @@ public void smallestPalindromeFromTripleDigitFactors() {
110117

111118
@Disabled("Remove to run test")
112119
@Test
120+
@DisplayName("find the smallest palindrome from four digit factors")
113121
public void smallestPalindromeFromQuadDigitFactors() {
114122
List<List<Integer>> expected = Collections.unmodifiableList(
115123
Arrays.asList(
@@ -126,6 +134,7 @@ public void smallestPalindromeFromQuadDigitFactors() {
126134

127135
@Disabled("Remove to run test")
128136
@Test
137+
@DisplayName("find the largest palindrome from four digit factors")
129138
public void largestPalindromeFromQuadDigitFactors() {
130139
List<List<Integer>> expected = Collections.unmodifiableList(
131140
Arrays.asList(
@@ -142,6 +151,7 @@ public void largestPalindromeFromQuadDigitFactors() {
142151

143152
@Disabled("Remove to run test")
144153
@Test
154+
@DisplayName("empty result for smallest if no palindrome in the range")
145155
public void emtpyResultSmallestNoPalindromeInRange() {
146156

147157
SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1002,
@@ -151,6 +161,7 @@ public void emtpyResultSmallestNoPalindromeInRange() {
151161

152162
@Disabled("Remove to run test")
153163
@Test
164+
@DisplayName("empty result for largest if no palindrome in the range")
154165
public void emptyResultLargestNoPalindromeInRange() {
155166

156167
SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(15,
@@ -160,6 +171,7 @@ public void emptyResultLargestNoPalindromeInRange() {
160171

161172
@Disabled("Remove to run test")
162173
@Test
174+
@DisplayName("error result for smallest if min is more than max")
163175
public void errorSmallestMinIsMoreThanMax() {
164176

165177
assertThatExceptionOfType(IllegalArgumentException.class)
@@ -169,6 +181,7 @@ public void errorSmallestMinIsMoreThanMax() {
169181

170182
@Disabled("Remove to run test")
171183
@Test
184+
@DisplayName("error result for largest if min is more than max")
172185
public void errorLargestMinIsMoreThanMax() {
173186

174187
assertThatExceptionOfType(IllegalArgumentException.class)
@@ -178,6 +191,7 @@ public void errorLargestMinIsMoreThanMax() {
178191

179192
@Disabled("Remove to run test")
180193
@Test
194+
@DisplayName("smallest product does not use the smallest factor")
181195
public void smallestProductDoesNotUseTheSmallestFactor() {
182196
List<List<Integer>> expected = Collections.unmodifiableList(
183197
Arrays.asList(

0 commit comments

Comments
 (0)