Sfoglia il codice sorgente

Merge pull request #1222 from TimoleonLatinopoulos/master

Added test cases as per #1161
Sam Warner 8 anni fa
parent
commit
ad7e33eb59
No account linked to committer's email

+ 1
- 1
exercises/bowling/.meta/src/reference/java/BowlingGame.java Vedi File

25
                 }
25
                 }
26
 
26
 
27
                 int strikeBonus = strikeBonus(frameIndex);
27
                 int strikeBonus = strikeBonus(frameIndex);
28
-                if (strikeBonus > MAXIMUM_FRAME_SCORE && !isStrike(frameIndex + 1)) {
28
+                if (strikeBonus > MAXIMUM_FRAME_SCORE && !isStrike(frameIndex + 1) || spareBonus(frameIndex) > 10) {
29
                     throw new IllegalStateException("Pin count exceeds pins on the lane");
29
                     throw new IllegalStateException("Pin count exceeds pins on the lane");
30
                 }
30
                 }
31
 
31
 

+ 1
- 0
exercises/bowling/.meta/version Vedi File

1
+1.1.0

+ 40
- 1
exercises/bowling/src/test/java/BowlingTest.java Vedi File

189
 
189
 
190
     @Ignore("Remove to run test")
190
     @Ignore("Remove to run test")
191
     @Test
191
     @Test
192
+    public void bonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
193
+        int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 0};
194
+
195
+        playGame(rolls);
196
+
197
+        expectedException.expect(IllegalStateException.class);
198
+        expectedException.expectMessage("Pin count exceeds pins on the lane");
199
+
200
+        game.score();
201
+    }
202
+    
203
+    @Ignore("Remove to run test")
204
+    @Test
192
     public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
205
     public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
193
         int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6};
206
         int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6};
194
 
207
 
209
 
222
 
210
         assertEquals(26, game.score());
223
         assertEquals(26, game.score());
211
     }
224
     }
225
+    
226
+    @Ignore("Remove to run test")
227
+    @Test
228
+    public void theSecondBonusRollsAfterAStrikeInTheLastFrameCanNotBeAStrikeIfTheFirstOneIsNotAStrike() {
229
+        int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6, 10};
212
 
230
 
231
+        playGame(rolls);
232
+
233
+        expectedException.expect(IllegalStateException.class);
234
+        expectedException.expectMessage("Pin count exceeds pins on the lane");
235
+
236
+        game.score();
237
+    }
238
+    
239
+    @Ignore("Remove to run test")
240
+    @Test
241
+    public void secondBonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
242
+        int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 11};
243
+
244
+        playGame(rolls);
245
+
246
+        expectedException.expect(IllegalStateException.class);
247
+        expectedException.expectMessage("Pin count exceeds pins on the lane");
248
+
249
+        game.score();
250
+    }
251
+    
213
     @Ignore("Remove to run test")
252
     @Ignore("Remove to run test")
214
     @Test
253
     @Test
215
     public void anUnstartedGameCanNotBeScored() {
254
     public void anUnstartedGameCanNotBeScored() {
238
 
277
 
239
     @Ignore("Remove to run test")
278
     @Ignore("Remove to run test")
240
     @Test
279
     @Test
241
-    public void aGameWithMoreThanTenFramesCanNotBeScored() {
280
+    public void canNotRollIfGameAlreadyHasTenFrames() {
242
         int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
281
         int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
243
 
282
 
244
         playGame(rolls);
283
         playGame(rolls);