Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions exercises/practice/hamming/src/test/java/HammingTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,36 +8,42 @@
public class HammingTest {

@Test
@DisplayName("empty strands")
public void testNoDistanceBetweenEmptyStrands() {
assertThat(new Hamming("", "").getHammingDistance()).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("single letter identical strands")
public void testNoDistanceBetweenShortIdenticalStrands() {
assertThat(new Hamming("A", "A").getHammingDistance()).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("single letter different strands")
public void testCompleteDistanceInSingleLetterDifferentStrands() {
assertThat(new Hamming("G", "T").getHammingDistance()).isEqualTo(1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("long identical strands")
public void testDistanceInLongIdenticalStrands() {
assertThat(new Hamming("GGACTGAAATCTG", "GGACTGAAATCTG").getHammingDistance()).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("long different strands")
public void testDistanceInLongDifferentStrands() {
assertThat(new Hamming("GGACGGATTCTG", "AGGACGGATTCT").getHammingDistance()).isEqualTo(9);
}

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("disallow left empty strand")
public void testDisallowLeftEmptyStrand() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new Hamming("", "G"))
Expand All @@ -61,6 +70,7 @@ public void testDisallowLeftEmptyStrand() {

@Disabled("Remove to run test")
@Test
@DisplayName("disallow right empty strand")
public void testDisallowRightEmptyStrand() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new Hamming("G", ""))
Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/hello-world/src/test/java/GreeterTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

public class GreeterTest {

@Test
@DisplayName("Say Hi!")
public void testThatGreeterReturnsTheCorrectGreeting() {
assertThat(new Greeter().getGreeting()).isEqualTo("Hello, World!");
}
Expand Down
13 changes: 13 additions & 0 deletions exercises/practice/high-scores/src/test/java/HighScoresTest.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
import java.util.Arrays;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

public class HighScoresTest {

@Test
@DisplayName("List of scores")
public void shouldReturnListOfScores() {
HighScores highScores = new HighScores(Arrays.asList(30, 50, 20, 70));
assertThat(highScores.scores()).isEqualTo(Arrays.asList(30, 50, 20, 70));
}

@Test
@Disabled("Remove to run test")
@DisplayName("Latest score")
public void shouldReturnLatestAddedScore() {
HighScores highScores = new HighScores(Arrays.asList(100, 0, 90, 30));
assertThat(highScores.latest()).isEqualTo(30);
}

@Test
@Disabled("Remove to run test")
@DisplayName("Personal best")
public void shouldReturnPersonalBest() {
HighScores highScores = new HighScores(Arrays.asList(40, 100, 70));
assertThat(highScores.personalBest()).isEqualTo(100);
}

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

@Test
@Disabled("Remove to run test")
@DisplayName("Personal top highest to lowest")
public void shouldReturnPersonalTopThreeSortedHighestToLowest() {
HighScores highScores = new HighScores(Arrays.asList(20, 10, 30));
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(30, 20, 10));
}

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

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

@Test
@Disabled("Remove to run test")
@DisplayName("Personal top when there is only one")
public void shouldReturnPersonalTopWhenThereIsOnlyOneScore() {
HighScores highScores = new HighScores(Arrays.asList(40));
assertThat(highScores.personalTopThree()).isEqualTo(Arrays.asList(40));
}

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

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

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

@Test
@Disabled("Remove to run test")
@DisplayName("Scores after personal best")
public void callingScoresAfterPersonalBest() {
HighScores highScores = new HighScores(Arrays.asList(20, 70, 15, 25, 30));
highScores.personalBest();
Expand Down
15 changes: 15 additions & 0 deletions exercises/practice/house/src/test/java/HouseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.BeforeEach;

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

@Test
@DisplayName("verse one - the house that jack built")
public void verseOne() {
assertThat(house.verse(1)).isEqualTo(
"This is the house that Jack built.");
}

@Disabled("Remove to run test")
@Test
@DisplayName("verse two - the malt that lay")
public void verseTwo() {
assertThat(house.verse(2)).isEqualTo(
"This is the malt " +
Expand All @@ -30,6 +33,7 @@ public void verseTwo() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse three - the rat that ate")
public void verseThree() {
assertThat(house.verse(3)).isEqualTo(
"This is the rat " +
Expand All @@ -39,6 +43,7 @@ public void verseThree() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse four - the cat that killed")
public void verseFour() {
assertThat(house.verse(4)).isEqualTo(
"This is the cat " +
Expand All @@ -49,6 +54,7 @@ public void verseFour() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse five - the dog that worried")
public void verseFive() {
assertThat(house.verse(5)).isEqualTo(
"This is the dog " +
Expand All @@ -60,6 +66,7 @@ public void verseFive() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse six - the cow with the crumpled horn")
public void verseSix() {
assertThat(house.verse(6)).isEqualTo(
"This is the cow with the crumpled horn " +
Expand All @@ -72,6 +79,7 @@ public void verseSix() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse seven - the maiden all forlorn")
public void verseSeven() {
assertThat(house.verse(7)).isEqualTo(
"This is the maiden all forlorn " +
Expand All @@ -85,6 +93,7 @@ public void verseSeven() {

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

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

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

@Disabled("Remove to run test")
@Test
@DisplayName("verse 11 - the farmer sowing his corn")
public void verse11() {
assertThat(house.verse(11)).isEqualTo(
"This is the farmer sowing his corn " +
Expand All @@ -147,6 +159,7 @@ public void verse11() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse 12 - the horse and the hound and the horn")
public void verse12() {
assertThat(house.verse(12)).isEqualTo(
"This is the horse and the hound and the horn " +
Expand All @@ -165,6 +178,7 @@ public void verse12() {

@Disabled("Remove to run test")
@Test
@DisplayName("multiple verses")
public void multipleVerses() {
int startVerse = 4;
int endVerse = 8;
Expand Down Expand Up @@ -204,6 +218,7 @@ public void multipleVerses() {

@Disabled("Remove to run test")
@Test
@DisplayName("full rhyme")
public void wholeRhyme() {
assertThat(house.sing()).isEqualTo(
"This is the house that Jack built.\n" +
Expand Down