Просмотр исходного кода

beer-song: update test suite to 2.1.0 (#1190)

* beer-song: update test suite to 2.1.0

* beer-song: use `takeDown` as test input instead of `stopVerse`

* beer-song: change all test instance of `verse(x)` to `sing(x, 1)`

* beer-song: make reference method private
Sam Warner 8 лет назад
Родитель
Сommit
4a791824cd

+ 5
- 4
exercises/beer-song/.meta/src/reference/java/BeerSong.java Просмотреть файл

1
 class BeerSong {
1
 class BeerSong {
2
-    String verse(int number) {
2
+    private String verse(int number) {
3
         switch (number) {
3
         switch (number) {
4
             case 0:
4
             case 0:
5
                 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";
5
                 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";
12
         }
12
         }
13
     }
13
     }
14
 
14
 
15
-    String sing(int start, int stop) {
15
+    String sing(int start, int takeDown) {
16
+        int stop = start - takeDown + 1;
16
         StringBuilder songOutput = new StringBuilder();
17
         StringBuilder songOutput = new StringBuilder();
17
 
18
 
18
         for (int i=start; i>=stop; i--) {
19
         for (int i=start; i>=stop; i--) {
23
     }
24
     }
24
 
25
 
25
     String singSong() {
26
     String singSong() {
26
-        return sing(99,0);
27
+        return sing(99, 100);
27
     }
28
     }
28
-}
29
+}

+ 1
- 0
exercises/beer-song/.meta/version Просмотреть файл

1
+2.1.0

+ 24
- 16
exercises/beer-song/src/test/java/BeerSongTest.java Просмотреть файл

17
     public void singFirstVerse() {
17
     public void singFirstVerse() {
18
         assertEquals("99 bottles of beer on the wall, 99 bottles of beer.\n" +
18
         assertEquals("99 bottles of beer on the wall, 99 bottles of beer.\n" +
19
                         "Take one down and pass it around, 98 bottles of beer on the wall.\n\n",
19
                         "Take one down and pass it around, 98 bottles of beer on the wall.\n\n",
20
-                beerSong.verse(99));
20
+                beerSong.sing(99, 1));
21
     }
21
     }
22
 
22
 
23
     @Ignore("Remove to run test")
23
     @Ignore("Remove to run test")
24
     @Test
24
     @Test
25
-    public void singMiddleVerse() {
26
-        assertEquals("44 bottles of beer on the wall, 44 bottles of beer.\n" +
27
-                        "Take one down and pass it around, 43 bottles of beer on the wall.\n\n",
28
-                beerSong.verse(44));
25
+    public void singLastGenericVerse() {
26
+        assertEquals("3 bottles of beer on the wall, 3 bottles of beer.\n" +
27
+                        "Take one down and pass it around, 2 bottles of beer on the wall.\n\n",
28
+                beerSong.sing(3, 1));
29
     }
29
     }
30
 
30
 
31
     @Ignore("Remove to run test")
31
     @Ignore("Remove to run test")
32
     @Test
32
     @Test
33
-    public void singThirdToLastVerse() {
33
+    public void verseWithTwoBottles() {
34
         assertEquals("2 bottles of beer on the wall, 2 bottles of beer.\n" +
34
         assertEquals("2 bottles of beer on the wall, 2 bottles of beer.\n" +
35
                         "Take one down and pass it around, 1 bottle of beer on the wall.\n\n",
35
                         "Take one down and pass it around, 1 bottle of beer on the wall.\n\n",
36
-                beerSong.verse(2));
36
+                beerSong.sing(2, 1));
37
     }
37
     }
38
 
38
 
39
     @Ignore("Remove to run test")
39
     @Ignore("Remove to run test")
40
     @Test
40
     @Test
41
-    public void singPenultimateVerse() {
41
+    public void verseWithOneBottle() {
42
         assertEquals("1 bottle of beer on the wall, 1 bottle of beer.\n" +
42
         assertEquals("1 bottle of beer on the wall, 1 bottle of beer.\n" +
43
                         "Take it down and pass it around, no more bottles of beer on the wall.\n\n",
43
                         "Take it down and pass it around, no more bottles of beer on the wall.\n\n",
44
-                beerSong.verse(1));
44
+                beerSong.sing(1, 1));
45
     }
45
     }
46
 
46
 
47
     @Ignore("Remove to run test")
47
     @Ignore("Remove to run test")
48
     @Test
48
     @Test
49
-    public void singLastVerse() {
49
+    public void verseWithZeroBottles() {
50
         assertEquals("No more bottles of beer on the wall, no more bottles of beer.\n" +
50
         assertEquals("No more bottles of beer on the wall, no more bottles of beer.\n" +
51
                         "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
51
                         "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
52
-                beerSong.verse(0));
52
+                beerSong.sing(0, 1));
53
     }
53
     }
54
 
54
 
55
     @Ignore("Remove to run test")
55
     @Ignore("Remove to run test")
56
     @Test
56
     @Test
57
-    public void singLastFourVerses() {
58
-        assertEquals("3 bottles of beer on the wall, 3 bottles of beer.\n" +
59
-                        "Take one down and pass it around, 2 bottles of beer on the wall.\n\n" +
60
-                        "2 bottles of beer on the wall, 2 bottles of beer.\n" +
57
+    public void singFirstTwoVerses() {
58
+        assertEquals("99 bottles of beer on the wall, 99 bottles of beer.\n" +
59
+                        "Take one down and pass it around, 98 bottles of beer on the wall.\n\n" +
60
+                        "98 bottles of beer on the wall, 98 bottles of beer.\n" +
61
+                        "Take one down and pass it around, 97 bottles of beer on the wall.\n\n",
62
+                beerSong.sing(99, 2));
63
+    }
64
+
65
+    @Ignore("Remove to run test")
66
+    @Test
67
+    public void singLastThreeVerses() {
68
+        assertEquals("2 bottles of beer on the wall, 2 bottles of beer.\n" +
61
                         "Take one down and pass it around, 1 bottle of beer on the wall.\n\n" +
69
                         "Take one down and pass it around, 1 bottle of beer on the wall.\n\n" +
62
                         "1 bottle of beer on the wall, 1 bottle of beer.\n" +
70
                         "1 bottle of beer on the wall, 1 bottle of beer.\n" +
63
                         "Take it down and pass it around, no more bottles of beer on the wall.\n\n" +
71
                         "Take it down and pass it around, no more bottles of beer on the wall.\n\n" +
64
                         "No more bottles of beer on the wall, no more bottles of beer.\n" +
72
                         "No more bottles of beer on the wall, no more bottles of beer.\n" +
65
                         "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
73
                         "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n",
66
-                beerSong.sing(3,0));
74
+                beerSong.sing(2, 3));
67
     }
75
     }
68
 
76
 
69
     @Ignore("Remove to run test")
77
     @Ignore("Remove to run test")