public
Created

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
Screw.Unit(function() {
describe("bowling game scorecard", function() {
var bowlingGame;
before(function() {
bowlingGame = new BowlingGame();
});
function gutterBall() {
bowlingGame.roll(0);
}
function strike() {
bowlingGame.roll(10);
}
describe("normal games", function() {
it("should score a single throw", function() {
bowlingGame.roll(5);
(19).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 5);
});
it("should score two throws which do not add up to a strike or spare", function() {
bowlingGame.roll(5);
bowlingGame.roll(4);
(18).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 9);
});
 
it("should score a spare", function() {
(3).times(function() { bowlingGame.roll(5); });
(17).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 20);
});
 
it("should score multiple spares", function() {
(2).times(function() { bowlingGame.roll(5); });
(2).times(function() { bowlingGame.roll(5); });
bowlingGame.roll(5);
(15).times(function(){ gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 35);
});
 
it("should score a strike", function() {
bowlingGame.roll(10);
bowlingGame.roll(5);
bowlingGame.roll(5);
(16).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 30);
});
 
it("should score back to back strikes", function() {
(2).times(function() { strike(); });
bowlingGame.roll(5);
bowlingGame.roll(4);
(14).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 53);
});
 
it("should score a combination of strikes and spares", function() {
(3).times(function() { strike(); });
(2).times(function() { bowlingGame.roll(5) });
bowlingGame.roll(7);
(15).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 99);
});
});
describe("special games", function() {
it("should score a full house of strikes", function() {
(12).times(function() { strike(); });
expect(bowlingGame.score()).to(equal, 300);
});
it("should score a full house of spares", function() {
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
gutterBall();
bowlingGame.roll(10);
bowlingGame.roll(10);
expect(bowlingGame.score()).to(equal, 110)
});
 
it("should score a gutter game", function() {
(10).times(function() { gutterBall(); });
 
expect(bowlingGame.score()).to(equal, 0);
});
it("should score a dutch 200", function() {
strike();
(2).times(function() { bowlingGame.roll(5) });
strike();
(2).times(function() { bowlingGame.roll(5) });
strike();
(2).times(function() { bowlingGame.roll(5) });
strike();
(2).times(function() { bowlingGame.roll(5) });
strike();
(2).times(function() { bowlingGame.roll(5) });
strike();
expect(bowlingGame.score()).to(equal, 200);
});
});
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.