git clone [email protected]:35d39ab94e659bff436fca096f2c5e37.git bowling
cd bowling
npm install
npm test
Last active
January 31, 2017 03:52
-
-
Save rmg/35d39ab94e659bff436fca096f2c5e37 to your computer and use it in GitHub Desktop.
Bowling Game Kata in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BowlingGame { | |
constructor() { | |
this.rolls = []; | |
} | |
roll(pins) { | |
this.rolls.push(pins); | |
} | |
score() { | |
return this.rolls.reduce((roll, total) => total + roll); | |
} | |
} | |
module.exports = BowlingGame; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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