Skip to content

Commit

Permalink
twelve-days: make use instance methods
Browse files Browse the repository at this point in the history
Fixes issue exercism#357.
  • Loading branch information
FridaTveit committed Mar 28, 2017
1 parent 8504152 commit a18cd41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions exercises/twelve-days/src/example/java/TwelveDays.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class TwelveDays {
"twelve Drummers Drumming, "
};

public static String verse(int verseNumber) {
public String verse(int verseNumber) {
return constructVerse(verseNumber);
}

public static String verses(int verseNumberStart, int verseNumberEnd) {
public String verses(int verseNumberStart, int verseNumberEnd) {
StringBuilder stringBuilder = new StringBuilder(constructVerse(verseNumberStart));
for (int i = verseNumberStart + 1; i <= verseNumberEnd; i++) {
stringBuilder.append("\n");
Expand All @@ -29,11 +29,11 @@ public static String verses(int verseNumberStart, int verseNumberEnd) {
return stringBuilder.toString();
}

public static String sing() {
public String sing() {
return verses(1, 12);
}

private static String constructVerse(int verseNumber) {
private String constructVerse(int verseNumber) {
StringBuilder stringBuilder = new StringBuilder("On the " + days[verseNumber - 1]
+ " day of Christmas my true love gave to me, ");
for (int i = verseNumber; i > 0; i--) {
Expand Down
35 changes: 21 additions & 14 deletions exercises/twelve-days/src/test/java/TwelveDaysTest.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TwelveDaysTest {
private TwelveDays twelveDays;

@Before
public void setup() {
twelveDays = new TwelveDays();
}

@Test
public void testVerseOne() {
String expectedVerseOne = "On the first day of Christmas my true love gave to me, " +
"a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseOne, TwelveDays.verse(1));
assertEquals(expectedVerseOne, twelveDays.verse(1));
}

@Ignore
@Test
public void testVerseTwo() {
String expectedVerseTwo = "On the second day of Christmas my true love gave to me, two Turtle Doves, " +
"and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseTwo, TwelveDays.verse(2));
assertEquals(expectedVerseTwo, twelveDays.verse(2));
}

@Ignore
@Test
public void testVerseThree() {
String expectedVerseThree = "On the third day of Christmas my true love gave to me, three French Hens, " +
"two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseThree, TwelveDays.verse(3));
assertEquals(expectedVerseThree, twelveDays.verse(3));
}

@Ignore
@Test
public void testVerseFour() {
String expectedVerseFour = "On the fourth day of Christmas my true love gave to me, four Calling Birds, " +
"three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseFour, TwelveDays.verse(4));
assertEquals(expectedVerseFour, twelveDays.verse(4));
}

@Ignore
@Test
public void testVerseFive() {
String expectedVerseFive = "On the fifth day of Christmas my true love gave to me, five Gold Rings, " +
"four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseFive, TwelveDays.verse(5));
assertEquals(expectedVerseFive, twelveDays.verse(5));
}

@Ignore
Expand All @@ -50,7 +57,7 @@ public void testVerseSix() {
String expectedVerseSix = "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, " +
"five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
"and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseSix, TwelveDays.verse(6));
assertEquals(expectedVerseSix, twelveDays.verse(6));
}

@Ignore
Expand All @@ -59,7 +66,7 @@ public void testVerseSeven() {
String expectedVerseSeven = "On the seventh day of Christmas my true love gave to me, " +
"seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, " +
"two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseSeven, TwelveDays.verse(7));
assertEquals(expectedVerseSeven, twelveDays.verse(7));
}

@Ignore
Expand All @@ -68,7 +75,7 @@ public void testVerseEight() {
String expectedVerseEight = "On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking," +
" seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
"three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseEight, TwelveDays.verse(8));
assertEquals(expectedVerseEight, twelveDays.verse(8));
}

@Ignore
Expand All @@ -77,7 +84,7 @@ public void testVerseNine() {
String expectedVerseNine = "On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, " +
"eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, " +
"four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseNine, TwelveDays.verse(9));
assertEquals(expectedVerseNine, twelveDays.verse(9));
}

@Ignore
Expand All @@ -87,7 +94,7 @@ public void testVerseTen() {
"nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, " +
"five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
"and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseTen, TwelveDays.verse(10));
assertEquals(expectedVerseTen, twelveDays.verse(10));
}

@Ignore
Expand All @@ -97,7 +104,7 @@ public void testVerseEleven() {
"eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, " +
"seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
"three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseEleven, TwelveDays.verse(11));
assertEquals(expectedVerseEleven, twelveDays.verse(11));
}

@Ignore
Expand All @@ -107,7 +114,7 @@ public void testVerseTwelve() {
"twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, " +
"eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, " +
"four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseTwelve, TwelveDays.verse(12));
assertEquals(expectedVerseTwelve, twelveDays.verse(12));
}

@Ignore
Expand All @@ -119,7 +126,7 @@ public void testMultipleVerses() {
"and a Partridge in a Pear Tree.\n\n" +
"On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, " +
"and a Partridge in a Pear Tree.\n";
assertEquals(expectedVerseOneToThree, TwelveDays.verses(1, 3));
assertEquals(expectedVerseOneToThree, twelveDays.verses(1, 3));
}

@Ignore
Expand Down Expand Up @@ -167,6 +174,6 @@ public void testSingWholeSong() {
"eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, " +
"seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
"three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
assertEquals(expectedSong, TwelveDays.sing());
assertEquals(expectedSong, twelveDays.sing());
}
}

0 comments on commit a18cd41

Please sign in to comment.