Skip to content

Commit 25ac571

Browse files
authored
Merge pull request exercism#404 from vasouv/beerSong-instance-methods
Beer song instance methods
2 parents 8504152 + 92a34f6 commit 25ac571

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
public class BeerSong {
2-
public static String verse(int number)
3-
{
4-
switch (number)
5-
{
2+
public String verse(int number) {
3+
switch (number) {
64
case 0:
75
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";
86
case 1:
@@ -14,8 +12,7 @@ public static String verse(int number)
1412
}
1513
}
1614

17-
public static String sing(int start, int stop)
18-
{
15+
public String sing(int start, int stop) {
1916
StringBuilder songOutput = new StringBuilder();
2017

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

28-
public static String singSong() {
25+
public String singSong() {
2926
return sing(99,0);
3027
}
3128
}

‎exercises/beer-song/src/test/java/BeerSongTest.java‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
11
import org.junit.Test;
22
import org.junit.Ignore;
3+
import org.junit.Before;
34

45
import static org.junit.Assert.assertEquals;
56

67
public class BeerSongTest {
78

9+
private BeerSong beerSong;
10+
11+
@Before
12+
public void setup(){
13+
beerSong = new BeerSong();
14+
}
15+
816
@Test
917
public void singFirstVerse() {
1018
assertEquals("99 bottles of beer on the wall, 99 bottles of beer.\n" +
1119
"Take one down and pass it around, 98 bottles of beer on the wall.\n\n",
12-
BeerSong.verse(99));
20+
beerSong.verse(99));
1321
}
1422

1523
@Ignore
1624
@Test
1725
public void singMiddleVerse() {
1826
assertEquals("44 bottles of beer on the wall, 44 bottles of beer.\n" +
1927
"Take one down and pass it around, 43 bottles of beer on the wall.\n\n",
20-
BeerSong.verse(44));
28+
beerSong.verse(44));
2129
}
2230

2331
@Ignore
2432
@Test
2533
public void singThirdToLastVerse() {
2634
assertEquals("2 bottles of beer on the wall, 2 bottles of beer.\n" +
2735
"Take one down and pass it around, 1 bottle of beer on the wall.\n\n",
28-
BeerSong.verse(2));
36+
beerSong.verse(2));
2937
}
3038

3139
@Ignore
3240
@Test
3341
public void singPenultimateVerse() {
3442
assertEquals("1 bottle of beer on the wall, 1 bottle of beer.\n" +
3543
"Take it down and pass it around, no more bottles of beer on the wall.\n\n",
36-
BeerSong.verse(1));
44+
beerSong.verse(1));
3745
}
3846

3947
@Ignore
4048
@Test
4149
public void singLastVerse() {
4250
assertEquals("No more bottles of beer on the wall, no more bottles of beer.\n" +
4351
"Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
44-
BeerSong.verse(0));
52+
beerSong.verse(0));
4553
}
4654

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

6169
@Ignore
@@ -161,7 +169,7 @@ public void singEntireSong() {
161169
"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" +
162170
"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" +
163171
"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",
164-
BeerSong.singSong());
172+
beerSong.singSong());
165173
}
166174

167175
}

0 commit comments

Comments
 (0)