GithubHelp home page GithubHelp logo

bowling-kata-demo's Introduction

Jest unit tests for Bowling Game Kata

This folder contains a unit test template for Jest.

Configured to support ES6 syntax using Babel (preset es2015)

Installation

npm install

Running the tests

npm test

Or you can use built-in watch mode:

npm run test:watch

Show coverage

npm run test:cover

Note: coverage is also included in watch mode.

Bowling Kata

Rules

  • Each game, or “line” of bowling, includes ten turns, or “frames” for the bowler.
  • In each frame, the bowler gets up to two tries to knock down all the pins.
  • If in two tries, he fails to knock them all down, his score for that frame is the total number of pins knocked down in his two tries.
  • If in two tries he knocks them all down, this is called a “spare” and his score for the frame is ten plus the number of pins knocked down on his next throw (in his next turn).
  • If on his first try in the frame he knocks down all the pins, this is called a “strike”. His turn is over, and his score for the frame is ten plus the simple total of the pins knocked down in his next two rolls.
  • If he gets a spare or strike in the last (tenth) frame, the bowler gets to throw one or two more bonus balls, respectively. These bonus throws are taken as part of the same turn. If the bonus throws knock down all the pins, the process does not repeat: the bonus throws are only used to calculate the score of the final frame.
  • The game score is the total of all frame scores.

Implementation

  • A class called Game is exported from game.js
  • The class has two methods:
    • roll(pins) which is called each time the player rolls a ball. The argument is the number of pins knocked down.
    • score() which is called only at the very end of the game. It returns the total score for that game.

Scoring example

  • Frame 1, ball 1: 10 pins (strike)
  • Frame 2, ball 1: 3 pins
  • Frame 2, ball 2: 6 pins
  • The total score from these throws is:
    • Frame one: 10 + (3 + 6) = 19
    • Frame two: 3 + 6 = 9
  • TOTAL = 28

Suggested Test Cases

(When scoring “X” indicates a strike, “/” indicates a spare, “-” indicates a miss)

  • 0 0 0 0 0 0 0 0 0 0 0 0 (12 rolls: 0 pins) = 10 frames * 0 points = 0
  • X X X X X X X X X X X X (12 rolls: 12 strikes) = 10 frames * 30 points = 300
  • 9- 9- 9- 9- 9- 9- 9- 9- 9- 9- (20 rolls: 10 pairs of 9 and miss) = 10 frames * 9 points = 90
  • 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/5 (21 rolls: 10 pairs of 5 and spare, with a final 5) = 10 frames * 15 points = 150

More info on the rules at:

More info on the kata at:

bowling-kata-demo's People

Contributors

anitawoodruff avatar christof-vollrath avatar coderbyheart avatar danshevluk avatar dbartholomae avatar dependabot[bot] avatar draptik avatar egga-zz avatar gabrielbotana avatar goerge avatar gvespucci avatar hellothisisflo avatar holsky avatar ikusalic avatar ilke-zilci avatar irinikp avatar jlink avatar kruglov-dmitry avatar larseckart avatar madduci avatar marcoemrich avatar mbde avatar miyamotoakira avatar mklose avatar mkrogemann avatar mrksdck avatar robertfirek avatar rradczewski avatar superzadeh avatar wonderbird avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.