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.

95 lines
2.3 KiB

4 years ago
4 years ago
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. @Test
  55. void frameWithStrikeCounts10() {
  56. // arrange
  57. String rolls = "-- -- X -- X -- -- -- -- --";
  58. int expectedScore = 20;
  59. // act
  60. int score = bowlingCalculator.score(rolls);
  61. // assert
  62. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  63. }
  64. @Test
  65. void frameWithStrikeAddsNextRollTwice() {
  66. // arrange
  67. String rolls = "-- -- X 2- X 8- -- -- -- --";
  68. int expectedScore = 40;
  69. // act
  70. int score = bowlingCalculator.score(rolls);
  71. // assert
  72. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  73. }@Test
  74. void frameWithStrikeAddsSecondNextRollTwice() {
  75. // arrange
  76. String rolls = "-- -- X -2 X -8 -- -- -- --";
  77. int expectedScore = 40;
  78. // act
  79. int score = bowlingCalculator.score(rolls);
  80. // assert
  81. assertThat("score", score, CoreMatchers.equalTo(expectedScore));
  82. }
  83. }