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.

62 lines
1.5 KiB

4 years ago
  1. package de.edu.hsfulda.ccip.tdd.purefunction;
  2. import static org.junit.Assert.assertThat;
  3. import static org.junit.jupiter.api.Assertions.*;
  4. import org.hamcrest.CoreMatchers;
  5. import org.junit.Assert;
  6. import org.junit.jupiter.api.BeforeEach;
  7. import org.junit.jupiter.api.Test;
  8. class BowlingCalculatorTest {
  9. private BowlingCalculator bowlingCalculator;
  10. @BeforeEach
  11. void setUp() throws Exception {
  12. bowlingCalculator = new BowlingCalculator();
  13. }
  14. @Test
  15. void resultOfWorstGameIsZero() {
  16. // arrange
  17. String rolls = "-- -- -- -- -- -- -- -- -- --";
  18. int expectedScore = 0;
  19. // act
  20. int score = bowlingCalculator.score(rolls);
  21. // assert
  22. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  23. }
  24. @Test
  25. void addUpSingleRollInIncompleteFrames() {
  26. // arrange
  27. String rolls = "-1 23 -4 5- -6 -7 8- 9- -- --";
  28. int expectedScore = 45;
  29. // act
  30. int score = bowlingCalculator.score(rolls);
  31. // assert
  32. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  33. }
  34. @Test
  35. void frameWithSpareCounts10() {
  36. // arrange
  37. String rolls = "-- -- 3/ -- 7/ -- -- -- -- --";
  38. int expectedScore = 20;
  39. // act
  40. int score = bowlingCalculator.score(rolls);
  41. // assert
  42. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  43. }
  44. @Test
  45. void frameWithSpareAddsNextRollTwice() {
  46. // arrange
  47. String rolls = "-- -- 3/ 2- 7/ 8- -- -- -- --";
  48. int expectedScore = 40;
  49. // act
  50. int score = bowlingCalculator.score(rolls);
  51. // assert
  52. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  53. }
  54. }