项目作者: ONSdigital

项目描述 :
Bowling game kata for ONS software development practices training
高级语言:
项目地址: git://github.com/ONSdigital/onse-bowling-game.git
创建时间: 2019-02-22T10:32:30Z
项目社区:https://github.com/ONSdigital/onse-bowling-game

开源协议:

下载


TDD Demo - Bowling Game Kata

This repository forms part of the ONS Software Development Practices
engineering training sessions. It contains a base project to run the bowling
game kata from.

Branches

  • master an empty project which can be used to practice/demonstrate the kata
  • completed a branch with the completed code and a commit history detailing
    each step.

Bowling Game Kata

The bowling game kata is a well know code kata. The aim is to use TDD to
implement a class which calculates the score of a 10 pin bowling game. The class
should have the following interface:

  1. class BowlingGame:
  2. def roll(self, pins):
  3. """
  4. Call this each time a ball is rolled passing in the number of pins that
  5. were knocked down.
  6. """
  7. def score(self):
  8. """
  9. Call this at the end of the game to get the final score.
  10. """

Rules of 10 Pin Bowling

  • A game has 10 frames
  • A player has 2 rolls per frame to try and knock down all 10 pins
  • If a player knocks down all 10 pins in a frame then they score a spare:
    • The score for a spare is the 10 pins plus the next roll as a bonus
  • If a player knocks down all 10 pins in the first roll of a frame then they
    score a strike:
    • If a strike is scored then there is no second roll in the frame
    • The score for a strike is the 10 pins plus the next 2 rolls as a bonus
    • If a strike is scored in the last frame then 2 bonus rolls are added to
      the frame
  • A perfect game is 12 successive strikes and scores 300 points

Exceptions & Edge Cases

For a real implementation of this you would want to check for errors, including
the following:

  • Negative number of pins passed to roll
  • More than 10 pins passed to roll
  • Score called before the game is completed
  • Roll called too many times

However, for this demonstration we are only focussing on the happy path.