Advertisement
Archon

TDD demo: spec

Aug 25th, 2021
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. A program to score a game of ten-pin Bowling.
  2.  
  3. Write a class named "Game" that has two methods:
  4. - roll(pins) is called each time the player rolls a ball. The argument is the number of
  5. pins knocked down.
  6. - score() is called only at the very end of the game. It returns the total score for
  7. that game.
  8.  
  9. Rules of ten-pin bowling:
  10. 1. The game consists of 10 frames. In each frame the player has two opportunities to
  11. knock down 10 pins. The score for the frame is the total number of pins knocked down,
  12. plus bonuses for strikes and spares.
  13. 2. A spare is when the player knocks down all 10 pins in two tries. The bonus for that
  14. frame is the number of pins knocked down by the next roll. So in frame 3 above, the
  15. score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins
  16. knocked down on the next roll.)
  17. 3. A strike is when the player knocks down all 10 pins on his first try. The bonus for
  18. that frame is the value of the next two balls rolled.
  19. 4. In the tenth frame a player who rolls a spare or strike is allowed to roll the extra
  20. balls to complete the frame. However no more than three balls can be rolled in tenth
  21. frame.
  22.  
  23. Steps in Test-Driven Development:
  24.  
  25. 1. WRITE A FAILING TEST.
  26. Write the shortest possible failing test that exercises the desired behaviour.
  27. Observe it failing in the expected way.
  28.  
  29. 2. MAKE IT PASS.
  30. Optimise for development speed. All tests should pass.
  31.  
  32. 3. REFACTOR
  33. Optionally, refactor the code, ensuring that the tests continue to pass.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement