Skip to content

Commit 988132d

Browse files
authored
hamming, hello-world, high-scores, house (#3009)
* hamming, hello-world, high-scores, house * Update HighScoresTest.java [no important files changed]
1 parent fb70422 commit 988132d

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

exercises/practice/hamming/src/test/java/HammingTest.java

Lines changed: 10 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 static org.assertj.core.api.Assertions.assertThat;
@@ -7,36 +8,42 @@
78
public class HammingTest {
89

910
@Test
11+
@DisplayName("empty strands")
1012
public void testNoDistanceBetweenEmptyStrands() {
1113
assertThat(new Hamming("", "").getHammingDistance()).isEqualTo(0);
1214
}
1315

1416
@Disabled("Remove to run test")
1517
@Test
18+
@DisplayName("single letter identical strands")
1619
public void testNoDistanceBetweenShortIdenticalStrands() {
1720
assertThat(new Hamming("A", "A").getHammingDistance()).isEqualTo(0);
1821
}
1922

2023
@Disabled("Remove to run test")
2124
@Test
25+
@DisplayName("single letter different strands")
2226
public void testCompleteDistanceInSingleLetterDifferentStrands() {
2327
assertThat(new Hamming("G", "T").getHammingDistance()).isEqualTo(1);
2428
}
2529

2630
@Disabled("Remove to run test")
2731
@Test
32+
@DisplayName("long identical strands")
2833
public void testDistanceInLongIdenticalStrands() {
2934
assertThat(new Hamming("GGACTGAAATCTG", "GGACTGAAATCTG").getHammingDistance()).isEqualTo(0);
3035
}
3136

3237
@Disabled("Remove to run test")
3338
@Test
39+
@DisplayName("long different strands")
3440
public void testDistanceInLongDifferentStrands() {
3541
assertThat(new Hamming("GGACGGATTCTG", "AGGACGGATTCT").getHammingDistance()).isEqualTo(9);
3642
}
3743

3844
@Disabled("Remove to run test")
3945
@Test
46+
@DisplayName("disallow first strand longer")
4047
public void testValidatesFirstStrandNotLonger() {
4148
assertThatExceptionOfType(IllegalArgumentException.class)
4249
.isThrownBy(() -> new Hamming("AATG", "AAA"))
@@ -45,6 +52,7 @@ public void testValidatesFirstStrandNotLonger() {
4552

4653
@Disabled("Remove to run test")
4754
@Test
55+
@DisplayName("disallow second strand longer")
4856
public void testValidatesSecondStrandNotLonger() {
4957
assertThatExceptionOfType(IllegalArgumentException.class)
5058
.isThrownBy(() -> new Hamming("ATA", "AGTG"))
@@ -53,6 +61,7 @@ public void testValidatesSecondStrandNotLonger() {
5361

5462
@Disabled("Remove to run test")
5563
@Test
64+
@DisplayName("disallow left empty strand")
5665
public void testDisallowLeftEmptyStrand() {
5766
assertThatExceptionOfType(IllegalArgumentException.class)
5867
.isThrownBy(() -> new Hamming("", "G"))
@@ -61,6 +70,7 @@ public void testDisallowLeftEmptyStrand() {
6170

6271
@Disabled("Remove to run test")
6372
@Test
73+
@DisplayName("disallow right empty strand")
6474
public void testDisallowRightEmptyStrand() {
6575
assertThatExceptionOfType(IllegalArgumentException.class)
6676
.isThrownBy(() -> new Hamming("G", ""))

exercises/practice/hello-world/src/test/java/GreeterTest.java

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

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

56
public class GreeterTest {
67

78
@Test
9+
@DisplayName("Say Hi!")
810
public void testThatGreeterReturnsTheCorrectGreeting() {
911
assertThat(new Greeter().getGreeting()).isEqualTo("Hello, World!");
1012
}

exercises/practice/high-scores/src/test/java/HighScoresTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,79 @@
11
import java.util.Arrays;
22

33
import org.junit.jupiter.api.Disabled;
4+
import org.junit.jupiter.api.DisplayName;
45
import org.junit.jupiter.api.Test;
56

67
import static org.assertj.core.api.Assertions.assertThat;
78

89
public class HighScoresTest {
910

1011
@Test
12+
@DisplayName("List of scores")
1113
public void shouldReturnListOfScores() {
1214
HighScores highScores = new HighScores(Arrays.asList(30, 50, 20, 70));
1315
assertThat(highScores.scores()).isEqualTo(Arrays.asList(30, 50, 20, 70));
1416
}
1517

1618
@Test
1719
@Disabled("Remove to run test")
20+
@DisplayName("Latest score")
1821
public void shouldReturnLatestAddedScore() {
1922
HighScores highScores = new HighScores(Arrays.asList(100, 0, 90, 30));
2023
assertThat(highScores.latest()).isEqualTo(30);
2124
}
2225

2326
@Test
2427
@Disabled("Remove to run test")
28+
@DisplayName("Personal best")
2529
public void shouldReturnPersonalBest() {
2630
HighScores highScores = new HighScores(Arrays.asList(40, 100, 70));
2731
assertThat(highScores.personalBest()).isEqualTo(100);
2832
}
2933

3034
@Test
3135
@Disabled("Remove to run test")
36+
@DisplayName("Personal top three from a list of scores")
3237
public void shouldReturnPersonalTopThreeFromListOfScores() {
3338
HighScores highScores = new HighScores(Arrays.asList(10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70));
3439
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(100, 90, 70));
3540
}
3641

3742
@Test
3843
@Disabled("Remove to run test")
44+
@DisplayName("Personal top highest to lowest")
3945
public void shouldReturnPersonalTopThreeSortedHighestToLowest() {
4046
HighScores highScores = new HighScores(Arrays.asList(20, 10, 30));
4147
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(30, 20, 10));
4248
}
4349

4450
@Test
4551
@Disabled("Remove to run test")
52+
@DisplayName("Personal top when there is a tie")
4653
public void shouldReturnPersonalTopThreeWhenThereIsATie() {
4754
HighScores highScores = new HighScores(Arrays.asList(40, 20, 40, 30));
4855
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(40, 40, 30));
4956
}
5057

5158
@Test
5259
@Disabled("Remove to run test")
60+
@DisplayName("Personal top when there are less than 3")
5361
public void shouldReturnPersonalTopWhenThereIsLessThanThreeScores() {
5462
HighScores highScores = new HighScores(Arrays.asList(30, 70));
5563
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(70, 30));
5664
}
5765

5866
@Test
5967
@Disabled("Remove to run test")
68+
@DisplayName("Personal top when there is only one")
6069
public void shouldReturnPersonalTopWhenThereIsOnlyOneScore() {
6170
HighScores highScores = new HighScores(Arrays.asList(40));
6271
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(40));
6372
}
6473

6574
@Test
6675
@Disabled("Remove to run test")
76+
@DisplayName("Latest score after personal top scores")
6777
public void callingLatestAfterPersonalTopThree() {
6878
HighScores highScores = new HighScores(Arrays.asList(70, 50, 20, 30));
6979
highScores.personalTopThree();
@@ -72,6 +82,7 @@ public void callingLatestAfterPersonalTopThree() {
7282

7383
@Test
7484
@Disabled("Remove to run test")
85+
@DisplayName("Scores after personal top scores")
7586
public void callingScoresAfterPersonalTopThree() {
7687
HighScores highScores = new HighScores(Arrays.asList(30, 50, 20, 70));
7788
highScores.personalTopThree();
@@ -80,6 +91,7 @@ public void callingScoresAfterPersonalTopThree() {
8091

8192
@Test
8293
@Disabled("Remove to run test")
94+
@DisplayName("Latest score after personal best")
8395
public void callingLatestAfterPersonalBest() {
8496
HighScores highScores = new HighScores(Arrays.asList(20, 70, 15, 25, 30));
8597
highScores.personalBest();
@@ -88,6 +100,7 @@ public void callingLatestAfterPersonalBest() {
88100

89101
@Test
90102
@Disabled("Remove to run test")
103+
@DisplayName("Scores after personal best")
91104
public void callingScoresAfterPersonalBest() {
92105
HighScores highScores = new HighScores(Arrays.asList(20, 70, 15, 25, 30));
93106
highScores.personalBest();

exercises/practice/house/src/test/java/HouseTest.java

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

56
import static org.assertj.core.api.Assertions.assertThat;
@@ -14,13 +15,15 @@ public void setup() {
1415
}
1516

1617
@Test
18+
@DisplayName("verse one - the house that jack built")
1719
public void verseOne() {
1820
assertThat(house.verse(1)).isEqualTo(
1921
"This is the house that Jack built.");
2022
}
2123

2224
@Disabled("Remove to run test")
2325
@Test
26+
@DisplayName("verse two - the malt that lay")
2427
public void verseTwo() {
2528
assertThat(house.verse(2)).isEqualTo(
2629
"This is the malt " +
@@ -30,6 +33,7 @@ public void verseTwo() {
3033

3134
@Disabled("Remove to run test")
3235
@Test
36+
@DisplayName("verse three - the rat that ate")
3337
public void verseThree() {
3438
assertThat(house.verse(3)).isEqualTo(
3539
"This is the rat " +
@@ -39,6 +43,7 @@ public void verseThree() {
3943

4044
@Disabled("Remove to run test")
4145
@Test
46+
@DisplayName("verse four - the cat that killed")
4247
public void verseFour() {
4348
assertThat(house.verse(4)).isEqualTo(
4449
"This is the cat " +
@@ -49,6 +54,7 @@ public void verseFour() {
4954

5055
@Disabled("Remove to run test")
5156
@Test
57+
@DisplayName("verse five - the dog that worried")
5258
public void verseFive() {
5359
assertThat(house.verse(5)).isEqualTo(
5460
"This is the dog " +
@@ -60,6 +66,7 @@ public void verseFive() {
6066

6167
@Disabled("Remove to run test")
6268
@Test
69+
@DisplayName("verse six - the cow with the crumpled horn")
6370
public void verseSix() {
6471
assertThat(house.verse(6)).isEqualTo(
6572
"This is the cow with the crumpled horn " +
@@ -72,6 +79,7 @@ public void verseSix() {
7279

7380
@Disabled("Remove to run test")
7481
@Test
82+
@DisplayName("verse seven - the maiden all forlorn")
7583
public void verseSeven() {
7684
assertThat(house.verse(7)).isEqualTo(
7785
"This is the maiden all forlorn " +
@@ -85,6 +93,7 @@ public void verseSeven() {
8593

8694
@Disabled("Remove to run test")
8795
@Test
96+
@DisplayName("verse eight - the man all tattered and torn")
8897
public void verseEight() {
8998
assertThat(house.verse(8)).isEqualTo(
9099
"This is the man all tattered and torn " +
@@ -99,6 +108,7 @@ public void verseEight() {
99108

100109
@Disabled("Remove to run test")
101110
@Test
111+
@DisplayName("verse nine - the priest all shaven and shorn")
102112
public void verseNine() {
103113
assertThat(house.verse(9)).isEqualTo(
104114
"This is the priest all shaven and shorn " +
@@ -114,6 +124,7 @@ public void verseNine() {
114124

115125
@Disabled("Remove to run test")
116126
@Test
127+
@DisplayName("verse 10 - the rooster that crowed in the morn")
117128
public void verse10() {
118129
assertThat(house.verse(10)).isEqualTo(
119130
"This is the rooster that crowed in the morn " +
@@ -130,6 +141,7 @@ public void verse10() {
130141

131142
@Disabled("Remove to run test")
132143
@Test
144+
@DisplayName("verse 11 - the farmer sowing his corn")
133145
public void verse11() {
134146
assertThat(house.verse(11)).isEqualTo(
135147
"This is the farmer sowing his corn " +
@@ -147,6 +159,7 @@ public void verse11() {
147159

148160
@Disabled("Remove to run test")
149161
@Test
162+
@DisplayName("verse 12 - the horse and the hound and the horn")
150163
public void verse12() {
151164
assertThat(house.verse(12)).isEqualTo(
152165
"This is the horse and the hound and the horn " +
@@ -165,6 +178,7 @@ public void verse12() {
165178

166179
@Disabled("Remove to run test")
167180
@Test
181+
@DisplayName("multiple verses")
168182
public void multipleVerses() {
169183
int startVerse = 4;
170184
int endVerse = 8;
@@ -204,6 +218,7 @@ public void multipleVerses() {
204218

205219
@Disabled("Remove to run test")
206220
@Test
221+
@DisplayName("full rhyme")
207222
public void wholeRhyme() {
208223
assertThat(house.sing()).isEqualTo(
209224
"This is the house that Jack built.\n" +

0 commit comments

Comments
 (0)