Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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,6 +15,7 @@ public void setup() {
}

@Test
@DisplayName("first generic verse")
public void firstGenericVerse() {
assertThat(bottleSong.recite(10, 1)).isEqualTo(
"Ten green bottles hanging on the wall,\n" +
Expand All @@ -25,6 +27,7 @@ public void firstGenericVerse() {

@Disabled("Remove to run test")
@Test
@DisplayName("last generic verse")
public void lastGenericVerse() {
assertThat(bottleSong.recite(3, 1)).isEqualTo(
"Three green bottles hanging on the wall,\n" +
Expand All @@ -36,6 +39,7 @@ public void lastGenericVerse() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse with 2 bottles")
public void verseWithTwoBottles() {
assertThat(bottleSong.recite(2, 1)).isEqualTo(
"Two green bottles hanging on the wall,\n" +
Expand All @@ -47,6 +51,7 @@ public void verseWithTwoBottles() {

@Disabled("Remove to run test")
@Test
@DisplayName("verse with 1 bottle")
public void verseWithOneBottle() {
assertThat(bottleSong.recite(1, 1)).isEqualTo(
"One green bottle hanging on the wall,\n" +
Expand All @@ -58,6 +63,7 @@ public void verseWithOneBottle() {

@Disabled("Remove to run test")
@Test
@DisplayName("first two verses")
public void firstTwoVerses() {
assertThat(bottleSong.recite(10, 2)).isEqualTo(
"Ten green bottles hanging on the wall,\n" +
Expand All @@ -74,6 +80,7 @@ public void firstTwoVerses() {

@Disabled("Remove to run test")
@Test
@DisplayName("last three verses")
public void lastThreeVerses() {
assertThat(bottleSong.recite(3, 3)).isEqualTo(
"Three green bottles hanging on the wall,\n" +
Expand All @@ -95,6 +102,7 @@ public void lastThreeVerses() {

@Disabled("Remove to run test")
@Test
@DisplayName("all verses")
public void allVerses() {
assertThat(bottleSong.recite(10, 10))
.isEqualTo(
Expand Down
34 changes: 34 additions & 0 deletions exercises/practice/bowling/src/test/java/BowlingGameTest.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 @@ -14,6 +15,7 @@ private void playGame(int[] rolls) {
}

@Test
@DisplayName("should be able to score a game with all zeros")
public void shouldBeAbleToScoreAGameWithAllZeros() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -23,6 +25,7 @@ public void shouldBeAbleToScoreAGameWithAllZeros() {

@Disabled("Remove to run test")
@Test
@DisplayName("should be able to score a game with no strikes or spares")
public void shouldBeAbleToScoreAGameWithNoStrikesOrSpares() {
int[] rolls = {3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6};

Expand All @@ -32,6 +35,7 @@ public void shouldBeAbleToScoreAGameWithNoStrikesOrSpares() {

@Disabled("Remove to run test")
@Test
@DisplayName("a spare followed by zeros is worth ten points")
public void aSpareFollowedByZerosIsWorthTenPoints() {
int[] rolls = {6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -41,6 +45,7 @@ public void aSpareFollowedByZerosIsWorthTenPoints() {

@Disabled("Remove to run test")
@Test
@DisplayName("points scored in the roll after a spare are counted twice")
public void pointsScoredInTheRollAfterASpareAreCountedTwice() {
int[] rolls = {6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -50,6 +55,7 @@ public void pointsScoredInTheRollAfterASpareAreCountedTwice() {

@Disabled("Remove to run test")
@Test
@DisplayName("consecutive spares each get a one roll bonus")
public void consecutiveSparesEachGetAOneRollBonus() {
int[] rolls = {5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -59,6 +65,7 @@ public void consecutiveSparesEachGetAOneRollBonus() {

@Disabled("Remove to run test")
@Test
@DisplayName("a spare in the last frame gets a one roll bonus that is counted once")
public void aSpareInTheLastFrameGetsAOneRollBonusThatIsCountedOnce() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 7};

Expand All @@ -68,6 +75,7 @@ public void aSpareInTheLastFrameGetsAOneRollBonusThatIsCountedOnce() {

@Disabled("Remove to run test")
@Test
@DisplayName("a strike earns ten points in a frame with a single roll")
public void aStrikeEarnsTenPointsInFrameWithASingleRoll() {
int[] rolls = {10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -77,6 +85,7 @@ public void aStrikeEarnsTenPointsInFrameWithASingleRoll() {

@Disabled("Remove to run test")
@Test
@DisplayName("points scored in the two rolls after a strike are counted twice as a bonus")
public void pointsScoredInTheTwoRollsAfterAStrikeAreCountedTwiceAsABonus() {
int[] rolls = {10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -86,6 +95,7 @@ public void pointsScoredInTheTwoRollsAfterAStrikeAreCountedTwiceAsABonus() {

@Disabled("Remove to run test")
@Test
@DisplayName("consecutive strikes each get the two roll bonus")
public void consecutiveStrikesEachGetTheTwoRollBonus() {
int[] rolls = {10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -95,6 +105,7 @@ public void consecutiveStrikesEachGetTheTwoRollBonus() {

@Disabled("Remove to run test")
@Test
@DisplayName("a strike in the last frame gets a two roll bonus that is counted once")
public void aStrikeInTheLastFrameGetsATwoRollBonusThatIsCountedOnce() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1};

Expand All @@ -104,6 +115,7 @@ public void aStrikeInTheLastFrameGetsATwoRollBonusThatIsCountedOnce() {

@Disabled("Remove to run test")
@Test
@DisplayName("rolling a spare with the two roll bonus does not get a bonus roll")
public void rollingASpareWithTheTwoRollBonusDoesNotGetABonusRoll() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 3};

Expand All @@ -113,6 +125,7 @@ public void rollingASpareWithTheTwoRollBonusDoesNotGetABonusRoll() {

@Disabled("Remove to run test")
@Test
@DisplayName("strikes with the two roll bonus do not get bonus rolls")
public void strikesWithTheTwoRollBonusDoNotGetBonusRolls() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10};

Expand All @@ -122,6 +135,7 @@ public void strikesWithTheTwoRollBonusDoNotGetBonusRolls() {

@Disabled("Remove to run test")
@Test
@DisplayName("last two strikes followed by only last bonus with non strike points")
public void lastTwoStrikesFollowedByOnlyLastBonusWithNonStrikePoints() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 0, 1};

Expand All @@ -131,6 +145,7 @@ public void lastTwoStrikesFollowedByOnlyLastBonusWithNonStrikePoints() {

@Disabled("Remove to run test")
@Test
@DisplayName("a strike with the one roll bonus after a spare in the last frame does not get a bonus")
public void aStrikeWithTheOneRollBonusAfterASpareInTheLastFrameDoesNotGetABonus() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 10};

Expand All @@ -140,6 +155,7 @@ public void aStrikeWithTheOneRollBonusAfterASpareInTheLastFrameDoesNotGetABonus(

@Disabled("Remove to run test")
@Test
@DisplayName("all strikes is a perfect game")
public void allStrikesIsAPerfectGame() {
int[] rolls = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};

Expand All @@ -149,6 +165,7 @@ public void allStrikesIsAPerfectGame() {

@Disabled("Remove to run test")
@Test
@DisplayName("rolls cannot score negative points")
public void rollsCanNotScoreNegativePoints() {
int[] rolls = {-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -159,6 +176,7 @@ public void rollsCanNotScoreNegativePoints() {

@Disabled("Remove to run test")
@Test
@DisplayName("a roll cannot score more than 10 points")
public void aRollCanNotScoreMoreThan10Points() {
int[] rolls = {11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -169,6 +187,7 @@ public void aRollCanNotScoreMoreThan10Points() {

@Disabled("Remove to run test")
@Test
@DisplayName("two rolls in a frame cannot score more than 10 points")
public void twoRollsInAFrameCanNotScoreMoreThan10Points() {
int[] rolls = {5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -179,6 +198,7 @@ public void twoRollsInAFrameCanNotScoreMoreThan10Points() {

@Disabled("Remove to run test")
@Test
@DisplayName("bonus roll after a strike in the last frame cannot score more than 10 points")
public void bonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 0};

Expand All @@ -189,6 +209,7 @@ public void bonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {

@Disabled("Remove to run test")
@Test
@DisplayName("two bonus rolls after a strike in the last frame cannot score more than 10 points")
public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6};

Expand All @@ -199,6 +220,7 @@ public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points()

@Disabled("Remove to run test")
@Test
@DisplayName("two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike")
public void twoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOneIsAStrike() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 6};

Expand All @@ -209,6 +231,9 @@ public void twoBonusRollsAfterAStrikeInTheLastFrameCanScoreMoreThan10PointsIfOne

@Disabled("Remove to run test")
@Test
@DisplayName(
"the second bonus rolls after a strike in the last frame cannot be a strike if the first one is not a strike"
)
public void theSecondBonusRollsAfterAStrikeInTheLastFrameCanNotBeAStrikeIfTheFirstOneIsNotAStrike() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6, 10};

Expand All @@ -219,6 +244,7 @@ public void theSecondBonusRollsAfterAStrikeInTheLastFrameCanNotBeAStrikeIfTheFir

@Disabled("Remove to run test")
@Test
@DisplayName("second bonus roll after a strike in the last frame cannot score more than 10 points")
public void secondBonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 11};

Expand All @@ -229,6 +255,7 @@ public void secondBonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points

@Disabled("Remove to run test")
@Test
@DisplayName("an unstarted game cannot be scored")
public void anUnstartedGameCanNotBeScored() {
int[] rolls = new int[0];

Expand All @@ -241,6 +268,7 @@ public void anUnstartedGameCanNotBeScored() {

@Disabled("Remove to run test")
@Test
@DisplayName("an incomplete game cannot be scored")
public void anIncompleteGameCanNotBeScored() {
int[] rolls = {0, 0};

Expand All @@ -253,6 +281,7 @@ public void anIncompleteGameCanNotBeScored() {

@Disabled("Remove to run test")
@Test
@DisplayName("cannot roll if game already has ten frames")
public void canNotRollIfGameAlreadyHasTenFrames() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

Expand All @@ -263,6 +292,7 @@ public void canNotRollIfGameAlreadyHasTenFrames() {

@Disabled("Remove to run test")
@Test
@DisplayName("bonus rolls for a strike in the last frame must be rolled before score can be calculated")
public void bonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10};

Expand All @@ -275,6 +305,7 @@ public void bonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalcul

@Disabled("Remove to run test")
@Test
@DisplayName("both bonus rolls for a strike in the last frame must be rolled before score can be calculated")
public void bothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10};

Expand All @@ -287,6 +318,7 @@ public void bothBonusRollsForAStrikeInTheLastFrameMustBeRolledBeforeScoreCanBeCa

@Disabled("Remove to run test")
@Test
@DisplayName("bonus roll for a spare in the last frame must be rolled before score can be calculated")
public void bonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculated() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3};

Expand All @@ -299,6 +331,7 @@ public void bonusRollForASpareInTheLastFrameMustBeRolledBeforeScoreCanBeCalculat

@Disabled("Remove to run test")
@Test
@DisplayName("cannot roll after bonus roll for spare")
public void canNotRollAfterBonusRollForSpare() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 2, 2};

Expand All @@ -309,6 +342,7 @@ public void canNotRollAfterBonusRollForSpare() {

@Disabled("Remove to run test")
@Test
@DisplayName("cannot roll after bonus rolls for strike")
public void canNotRollAfterBonusRollForStrike() {
int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 3, 2, 2};

Expand Down
Loading