Skip to content

Instantly share code, notes, and snippets.

@rmg
Last active January 31, 2017 03:52
Show Gist options
  • Save rmg/35d39ab94e659bff436fca096f2c5e37 to your computer and use it in GitHub Desktop.
Save rmg/35d39ab94e659bff436fca096f2c5e37 to your computer and use it in GitHub Desktop.
Bowling Game Kata in JavaScript

Bowling Game Kata in JavaScript

git clone [email protected]:35d39ab94e659bff436fca096f2c5e37.git bowling
cd bowling
npm install
npm test
class BowlingGame {
constructor() {
this.rolls = [];
}
roll(pins) {
this.rolls.push(pins);
}
score() {
return this.rolls.reduce((roll, total) => total + roll);
}
}
module.exports = BowlingGame;
{
"name": "bowling",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "tap test.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"tap": "^10.0.0"
},
"engines": {
"node": ">=6"
}
}
var BowlingGame = require('./');
var tap = require('tap');
tap.test('Scoring Bowling Games', function(t) {
var game;
t.beforeEach(function(done) {
game = new BowlingGame();
done();
});
t.test('should show that tests are working', function(t) {
t.ok(game);
t.end();
});
t.test('should sum a bad game', function(t) {
for (let i = 0; i < 20; i++) {
game.roll(0);
}
t.equal(game.score(), 0);
t.end();
});
t.test('should sum a mediocre game', function(t) {
for (let i = 0; i < 20; i++) {
game.roll(5);
}
t.equal(game.score(), 100);
t.end();
});
t.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment