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
11 changes: 4 additions & 7 deletions exercises/beer-song/src/example/java/BeerSong.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
public class BeerSong {
public static String verse(int number)
{
switch (number)
{
public String verse(int number) {
switch (number) {
case 0:
return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n\n";
case 1:
Expand All @@ -14,8 +12,7 @@ public static String verse(int number)
}
}

public static String sing(int start, int stop)
{
public String sing(int start, int stop) {
StringBuilder songOutput = new StringBuilder();

for (int i=start; i>=stop; i--) {
Expand All @@ -25,7 +22,7 @@ public static String sing(int start, int stop)
return songOutput.toString();
}

public static String singSong() {
public String singSong() {
return sing(99,0);
}
}
22 changes: 15 additions & 7 deletions exercises/beer-song/src/test/java/BeerSongTest.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Before;

import static org.junit.Assert.assertEquals;

public class BeerSongTest {

private BeerSong beerSong;

@Before
public void setup(){
beerSong = new BeerSong();
}

@Test
public void singFirstVerse() {
assertEquals("99 bottles of beer on the wall, 99 bottles of beer.\n" +
"Take one down and pass it around, 98 bottles of beer on the wall.\n\n",
BeerSong.verse(99));
beerSong.verse(99));
}

@Ignore
@Test
public void singMiddleVerse() {
assertEquals("44 bottles of beer on the wall, 44 bottles of beer.\n" +
"Take one down and pass it around, 43 bottles of beer on the wall.\n\n",
BeerSong.verse(44));
beerSong.verse(44));
}

@Ignore
@Test
public void singThirdToLastVerse() {
assertEquals("2 bottles of beer on the wall, 2 bottles of beer.\n" +
"Take one down and pass it around, 1 bottle of beer on the wall.\n\n",
BeerSong.verse(2));
beerSong.verse(2));
}

@Ignore
@Test
public void singPenultimateVerse() {
assertEquals("1 bottle of beer on the wall, 1 bottle of beer.\n" +
"Take it down and pass it around, no more bottles of beer on the wall.\n\n",
BeerSong.verse(1));
beerSong.verse(1));
}

@Ignore
@Test
public void singLastVerse() {
assertEquals("No more bottles of beer on the wall, no more bottles of beer.\n" +
"Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
BeerSong.verse(0));
beerSong.verse(0));
}

@Ignore
Expand All @@ -55,7 +63,7 @@ public void singLastFourVerses() {
"Take it down and pass it around, no more bottles of beer on the wall.\n\n" +
"No more bottles of beer on the wall, no more bottles of beer.\n" +
"Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
BeerSong.sing(3,0));
beerSong.sing(3,0));
}

@Ignore
Expand Down Expand Up @@ -161,7 +169,7 @@ public void singEntireSong() {
"2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n" +
"1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\n" +
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n\n",
BeerSong.singSong());
beerSong.singSong());
}

}