Code Kata Report
diff -r 8a3ed4fb1f9a -r 629b00541148 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 11:50:32 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 11:54:31 2012 -0500 @@ -8,16 +8,23 @@ public class BowlingGameTest { private BowlingGame instance = new BowlingGame(); - - @Test public void shouldCalculateScoreForZeroGame() { for (int i = 0; i < 20; ++i) { instance.roll(0); } assertThat(instance.score(), is(0)); } + + @Test + public void shouldCalculateScoreOfOne() { + for (int i = 0; i < 19; i++) { + instance.roll(0); + } + instance.roll(1); + assertThat(instance.score(), is(1)); + } } diff -r 8a3ed4fb1f9a -r 629b00541148 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 11:50:32 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 11:54:31 2012 -0500 @@ -1,12 +1,15 @@ package com.tuck.testing; public class BowlingGame { + private int score = 0; + public void roll(int pins) { + score += pins; } public int score() { - return 0; + return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 629b00541148 -r 27bfe1dab6e5 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 11:54:31 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:13:56 2012 -0500 @@ -24,7 +24,19 @@ instance.roll(0); } instance.roll(1); assertThat(instance.score(), is(1)); } + + @Test + public void shouldCalculateStrike() { + instance.roll(10); + instance.roll(1); + + for (int i = 0; i < 17; i++){ + instance.roll(0); + } + + assertThat(instance.score(), is(12)); + } } diff -r 629b00541148 -r 27bfe1dab6e5 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 11:54:31 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:13:56 2012 -0500 @@ -1,15 +1,25 @@ package com.tuck.testing; + +import java.util.ArrayList; +import java.util.List; public class BowlingGame { private int score = 0; + private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { - score += pins; + rolls.add(pins); } public int score() { + for (int i=0; i<rolls.size(); i++) { + score += rolls.get(i); + if (rolls.get(i) == 10) { + score += rolls.get(i + 1); + } + } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 27bfe1dab6e5 -r 5152baa9cedf src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:13:56 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:16:33 2012 -0500 @@ -1,25 +1,26 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { - private int score = 0; + private static final int STRIKE = 10; private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { + int score = 0; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); - if (rolls.get(i) == 10) { + if (rolls.get(i) == STRIKE) { score += rolls.get(i + 1); } } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 5152baa9cedf -r 601394e2b8e2 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:16:33 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:24:06 2012 -0500 @@ -10,33 +10,44 @@ private BowlingGame instance = new BowlingGame(); @Test public void shouldCalculateScoreForZeroGame() { - for (int i = 0; i < 20; ++i) { - instance.roll(0); - } + gutterRest(20); assertThat(instance.score(), is(0)); } @Test public void shouldCalculateScoreOfOne() { - for (int i = 0; i < 19; i++) { - instance.roll(0); - } instance.roll(1); + gutterRest(19); assertThat(instance.score(), is(1)); } @Test public void shouldCalculateStrike() { instance.roll(10); instance.roll(1); - for (int i = 0; i < 17; i++){ - instance.roll(0); - } + gutterRest(17); assertThat(instance.score(), is(12)); } + + @Test + public void strikeShouldAddNextTwoRolls() { + instance.roll(10); + instance.roll(1); + instance.roll(1); + gutterRest(16); + assertThat(instance.score(), is(14)); + } + + + + private void gutterRest(int rolls) { + for (int i = 0; i < rolls; i++){ + instance.roll(0); + } + } } diff -r 5152baa9cedf -r 601394e2b8e2 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:16:33 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:24:06 2012 -0500 @@ -1,26 +1,27 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { private static final int STRIKE = 10; private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); if (rolls.get(i) == STRIKE) { score += rolls.get(i + 1); + score += rolls.get(i + 2); } } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 601394e2b8e2 -r 92fa087bd231 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:24:06 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:34:28 2012 -0500 @@ -40,11 +40,20 @@ instance.roll(1); gutterRest(16); assertThat(instance.score(), is(14)); } - + @Test + public void spareShouldTakeOneRoll() { + instance.roll(1); + instance.roll(9); + instance.roll(1); + gutterRest(17); + assertThat(instance.score(), is(12)); + } + + private void gutterRest(int rolls) { for (int i = 0; i < rolls; i++){ instance.roll(0); } diff -r 601394e2b8e2 -r 92fa087bd231 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:24:06 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:34:28 2012 -0500 @@ -1,27 +1,39 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { private static final int STRIKE = 10; private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; + + boolean firstBall = true; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); if (rolls.get(i) == STRIKE) { score += rolls.get(i + 1); score += rolls.get(i + 2); + firstBall = true; + } else if (!firstBall) { + firstBall = true; + + //Check for spares + if (rolls.get(i-1) + rolls.get(i) == 10) { + score += rolls.get(i + 1); + } + } else { + firstBall = false; } } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 92fa087bd231 -r 884d0cc7cf4d src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:34:28 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:40:01 2012 -0500 @@ -49,10 +49,12 @@ instance.roll(1); gutterRest(17); assertThat(instance.score(), is(12)); } + + private void gutterRest(int rolls) { for (int i = 0; i < rolls; i++){ instance.roll(0); diff -r 92fa087bd231 -r 884d0cc7cf4d src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:34:28 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:40:01 2012 -0500 @@ -1,39 +1,41 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { - - private static final int STRIKE = 10; private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; boolean firstBall = true; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); - if (rolls.get(i) == STRIKE) { - score += rolls.get(i + 1); - score += rolls.get(i + 2); + + if (!firstBall) { firstBall = true; - } else if (!firstBall) { - firstBall = true; - + //Check for spares if (rolls.get(i-1) + rolls.get(i) == 10) { score += rolls.get(i + 1); } } else { firstBall = false; + + //Check for strike + if (rolls.get(i) == 10) { + score += rolls.get(i + 1); + score += rolls.get(i + 2); + firstBall = true; + } } } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 884d0cc7cf4d -r 5a42ff74be38 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:40:01 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 12:49:59 2012 -0500 @@ -49,12 +49,28 @@ instance.roll(1); gutterRest(17); assertThat(instance.score(), is(12)); } - + @Test + public void spareThenStrike() { + instance.roll(1); + instance.roll(9); + instance.roll(10); + gutterRest(16); + assertThat(instance.score(), is(30)); + } + @Test + public void tenthFrameStrike() { + gutterRest(18); + instance.roll(10); + instance.roll(1); + instance.roll(0); + + assertThat(instance.score(), is(11)); + } private void gutterRest(int rolls) { for (int i = 0; i < rolls; i++){ instance.roll(0); diff -r 884d0cc7cf4d -r 5a42ff74be38 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:40:01 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:49:59 2012 -0500 @@ -1,41 +1,43 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; + boolean firstBall = true; + int currentFrame = 1; - boolean firstBall = true; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); - if (!firstBall) { - firstBall = true; - + if (firstBall) { + firstBall = false; + //Check for strike + if (rolls.get(i) == 10 && currentFrame != 10) { + score += rolls.get(i + 1); + score += rolls.get(i + 2); + firstBall = true; + currentFrame++; + } + } else { //Check for spares if (rolls.get(i-1) + rolls.get(i) == 10) { score += rolls.get(i + 1); } - } else { - firstBall = false; - //Check for strike - if (rolls.get(i) == 10) { - score += rolls.get(i + 1); - score += rolls.get(i + 2); - firstBall = true; - } + firstBall = true; + currentFrame++; } } return score; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 5a42ff74be38 -r c50200861e5f src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 12:49:59 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 13:04:56 2012 -0500 @@ -1,43 +1,45 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; boolean firstBall = true; int currentFrame = 1; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); if (firstBall) { firstBall = false; - //Check for strike - if (rolls.get(i) == 10 && currentFrame != 10) { + if (shouldCalculateStrike(i, currentFrame)) { score += rolls.get(i + 1); score += rolls.get(i + 2); firstBall = true; currentFrame++; } } else { //Check for spares if (rolls.get(i-1) + rolls.get(i) == 10) { score += rolls.get(i + 1); } - firstBall = true; currentFrame++; } } return score; } + private boolean shouldCalculateStrike(int currentRoll, int currentFrame) { + return rolls.get(currentRoll) == 10 && currentFrame != 10; + } + } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r c50200861e5f -r a2f7dde177c9 src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 13:04:56 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 13:42:52 2012 -0500 @@ -50,11 +50,11 @@ gutterRest(17); assertThat(instance.score(), is(12)); } @Test - public void spareThenStrike() { + public void calculateOfSpareStrikeShouldAdd10BonusPins() { instance.roll(1); instance.roll(9); instance.roll(10); gutterRest(16); assertThat(instance.score(), is(30)); @@ -68,10 +68,20 @@ instance.roll(0); assertThat(instance.score(), is(11)); } + @Test + public void tenthFrameSpareScoreShouldNotBeTreatedSpecial() { + gutterRest(18); + instance.roll(4); + instance.roll(6); + instance.roll(1); + + assertThat(instance.score(), is(11)); + } + private void gutterRest(int rolls) { for (int i = 0; i < rolls; i++){ instance.roll(0); } diff -r c50200861e5f -r a2f7dde177c9 src/main/java/com/tuck/testing/BowlingGame.java --- a/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 13:04:56 2012 -0500 +++ b/src/main/java/com/tuck/testing/BowlingGame.java Wed Mar 28 13:42:52 2012 -0500 @@ -1,45 +1,45 @@ package com.tuck.testing; import java.util.ArrayList; import java.util.List; public class BowlingGame { private List<Integer> rolls = new ArrayList<Integer>(); public void roll(int pins) { rolls.add(pins); } public int score() { int score = 0; boolean firstBall = true; int currentFrame = 1; for (int i=0; i<rolls.size(); i++) { score += rolls.get(i); if (firstBall) { firstBall = false; if (shouldCalculateStrike(i, currentFrame)) { score += rolls.get(i + 1); score += rolls.get(i + 2); firstBall = true; currentFrame++; } } else { //Check for spares - if (rolls.get(i-1) + rolls.get(i) == 10) { + if (rolls.get(i-1) + rolls.get(i) == 10 && currentFrame != 10) { score += rolls.get(i + 1); } firstBall = true; currentFrame++; } } return score; } private boolean shouldCalculateStrike(int currentRoll, int currentFrame) { return rolls.get(currentRoll) == 10 && currentFrame != 10; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r a2f7dde177c9 -r 7d73d46e239b src/test/java/com/tuck/testing/BowlingGameTest.java --- a/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 13:42:52 2012 -0500 +++ b/src/test/java/com/tuck/testing/BowlingGameTest.java Wed Mar 28 13:48:08 2012 -0500 @@ -78,10 +78,18 @@ instance.roll(1); assertThat(instance.score(), is(11)); } + @Test + public void allStrikeGameShouldScore300() { + for (int i = 0; i < 12; i++){ + instance.roll(10); + } + + assertThat(instance.score(), is(300)); + } private void gutterRest(int rolls) { for (int i = 0; i < rolls; i++){ instance.roll(0); }