You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
993 B

  1. import org.junit.jupiter.params.ParameterizedTest;
  2. import org.junit.jupiter.params.provider.Arguments;
  3. import org.junit.jupiter.params.provider.MethodSource;
  4. import java.util.stream.Stream;
  5. import static org.junit.jupiter.api.Assertions.assertEquals;
  6. public class BowlingCalculatorTest {
  7. @ParameterizedTest(name = "[{index}] {0} scores {2}")
  8. @MethodSource("playerResults")
  9. void test(String testName, String playerResult, int expectedScore) {
  10. BowlingGameCalculator bgc = new BowlingGameCalculator();
  11. int calculatedScore = bgc.score(playerResult);
  12. assertEquals(expectedScore, calculatedScore, String.format("%s: %s", testName, playerResult));
  13. }
  14. private static Stream<Arguments> playerResults() {
  15. return Stream.of(
  16. 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
  17. 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)
  18. );
  19. }
  20. }