Browse Source

add spare counts 10 test with unfinished implementation

master
binsky 3 years ago
parent
commit
75824ced3e
  1. 17
      src/main/java/BowlingGameCalculator.java
  2. 3
      src/test/java/BowlingCalculatorTest.java
  3. BIN
      target/classes/BowlingGameCalculator.class
  4. BIN
      target/test-classes/BowlingCalculatorTest.class

17
src/main/java/BowlingGameCalculator.java

@ -5,25 +5,16 @@ import java.util.regex.Pattern;
public class BowlingGameCalculator { public class BowlingGameCalculator {
private static final Pattern SINGLE_VALUE_PATTERN = Pattern.compile("\\d"); private static final Pattern SINGLE_VALUE_PATTERN = Pattern.compile("\\d");
private static final Pattern SPARE_PATTERN = Pattern.compile("/[ -,]*(\\d)");
private static final Pattern SPARE_PATTERN = Pattern.compile("(\\d)[ ,]*/[ -,]*(\\d)");
private static final int INITIAL_SCORE_VALUE = 0; private static final int INITIAL_SCORE_VALUE = 0;
public int score(String playerResult) { public int score(String playerResult) {
int playerScore = INITIAL_SCORE_VALUE; int playerScore = INITIAL_SCORE_VALUE;
/*
Matcher singleDigit = SINGLE_VALUE_PATTERN.matcher(playerResult);
while (singleDigit.find()) {
playerScore += Integer.parseInt(singleDigit.group());
}
Matcher spare = SPARE_PATTERN.matcher(playerResult);
Function<Matcher, Integer> spareScorer = (spareMatcher) -> 10 + Integer.parseInt(spare.group(1));
playerScore = scoreMatch(playerScore, spare, spareScorer);
*/
playerScore += scoreMatch(SINGLE_VALUE_PATTERN.matcher(playerResult), (spareMatcher) -> Integer.parseInt(spareMatcher.group())); playerScore += scoreMatch(SINGLE_VALUE_PATTERN.matcher(playerResult), (spareMatcher) -> Integer.parseInt(spareMatcher.group()));
playerScore += scoreMatch(SPARE_PATTERN.matcher(playerResult), (spareMatcher) -> 10 + Integer.parseInt(spareMatcher.group(1)));
playerScore += scoreMatch(SPARE_PATTERN.matcher(playerResult), (spareMatcher) ->
10 + Integer.parseInt(spareMatcher.group(2))
- Integer.parseInt(spareMatcher.group(1)));
return playerScore; return playerScore;
} }

3
src/test/java/BowlingCalculatorTest.java

@ -23,7 +23,8 @@ public class BowlingCalculatorTest {
Arguments.of("worst game", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", 0), // 20x 0 Arguments.of("worst game", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", 0), // 20x 0
Arguments.of("some incomplete frames", "0,1,2,3,0,0,4,0,0,5,0,0,6,0,0,0,0,0,0,0", 21), Arguments.of("some incomplete frames", "0,1,2,3,0,0,4,0,0,5,0,0,6,0,0,0,0,0,0,0", 21),
Arguments.of("some other incomplete frames", "9- 9- 9- 9- 9- 9- 9- 9- 9- 9-", 90), Arguments.of("some other incomplete frames", "9- 9- 9- 9- 9- 9- 9- 9- 9- 9-", 90),
Arguments.of("roll after spare counts twice", "0,0 ,0,/ ,1,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0", 12) // Wurf nach Spare (/) zählt doppelt
Arguments.of("roll after spare counts twice", "0,0 ,0,/ ,1,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0", 12), // Wurf nach Spare (/) zählt doppelt
Arguments.of("spare counts 10", "5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/5", 150)
); );
} }
} }

BIN
target/classes/BowlingGameCalculator.class

BIN
target/test-classes/BowlingCalculatorTest.class

Loading…
Cancel
Save