Skip to content

Commit

Permalink
Added jasmine node totest through command line; Added ESLint: Ran bea…
Browse files Browse the repository at this point in the history
…utifier with new rules on all files
  • Loading branch information
Sam authored and Sam committed Jul 8, 2017
1 parent 4f5b560 commit d160783
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 167 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,47 @@ Bowling Challenge

To run tests type the following in your terminal:

'''
$ git clone https://github.com/sblausten/bowling-challenge.git
$ cd bowling-challenge
$ open SpecRunner.html
'''bash
git clone https://github.com/sblausten/bowling-challenge.git
cd bowling-challenge
open SpecRunner.html
'''

## User stories

- As a player
- As a player
so that I can play
I want to start a game of bowling

- As a player
so that I can score
I want to roll
- As a player
so that I can score
I want to roll

- As a player
I want to have two rolls per frame

- As a player
I want to end a frame when I score 10 in first roll

- As a player
- As a player
I want to keep track of my score for each roll including skipped ones

- As a player
- As a player
I want to keep track of my score for each frame including bonuses

As a player
As a player
I want to add this frame to the last frame if it was a strike

As a player
As a player
I want to add the first roll to the last frame if it was a spare

As a player
- As a player
I want the game to end after 10 frames

As a player
I want the game to continue after 10 frames if the last frame is a strike

As a player
- As a player
I want the game to only continue past 10 frames when the frame is a strike

As a player
- As a player
I want the game to end after 13 frames if the last four frames are strikes.


Expand Down
2 changes: 2 additions & 0 deletions SpecRunner.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.6.1</title>
Expand All @@ -26,4 +27,5 @@

<body>
</body>

</html>
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "1.0.0",
"description": "bowlin-challenge",
"main": "index.js",
"scripts": {
"test": "jasmine-node spec",
"lint": "eslint ./src"
},
"directories": {
"doc": "docs"
},
Expand All @@ -12,11 +16,11 @@
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"eslint-plugin-standard": "^3.0.1",
"jasmine-node": "^1.14.5"
},
"repository": {
"type": "git",
Expand Down
90 changes: 45 additions & 45 deletions spec/FrameSpec.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
'use strict';

describe('Frame', function() {
var frame;
beforeEach(function() {
frame = new Frame();
var frame;
beforeEach(function() {
frame = new Frame();
});
describe('roll', function() {
it('returns a number between 0 and 10', function() {
frame.roll();
expect(frame.getScore()[0]).toBeLessThan(11);
});
describe('roll', function() {
it('returns a number between 0 and 10', function() {
frame.roll();
expect(frame.getScore()[0]).toBeLessThan(11);
});
it('does not roll more than 2 times', function() {
for (var i = 0; i < 3; i++) {
frame.roll();
}
expect(frame.getScore().length).toBeLessThan(3);
});
it('does not roll more than 2 times', function() {
for (var i = 0; i < 3; i++) {
frame.roll();
}
expect(frame.getScore().length).toBeLessThan(3);
});
describe('isSpare', function() {
it('sets this.spare to true when first and second score = 10', function() {
spyOn(Math, "random").and.returnValues(0.51, 0.9);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([5, 5]);
expect(frame.getSpare()).toBeTrue;
});
it('does not set spare to true when strike', function() {
spyOn(Math, "random").and.returnValue(0.97);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([10, 0]);
expect(frame.getSpare()).toBeFalse;
});
});
describe('isSpare', function() {
it('sets this.spare to true when first and second score = 10', function() {
spyOn(Math, "random").and.returnValues(0.51, 0.9);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([5, 5]);
expect(frame.getSpare()).toBeTrue;
});
describe('isStrike', function() {
it('sets this.strike to true when first score = 10', function() {
spyOn(Math, "random").and.returnValues(0.95, 0.5);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([10, 0]);
expect(frame.getStrike()).toBeTrue;
});
it('does not set strike to true when second roll is 10', function() {
spyOn(Math, "random").and.returnValues(0, 0.97);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([0, 10]);
expect(frame.getStrike()).toBeFalse;
});
it('does not set spare to true when strike', function() {
spyOn(Math, "random").and.returnValue(0.97);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([10, 0]);
expect(frame.getSpare()).toBeFalse;
});
});
});
describe('isStrike', function() {
it('sets this.strike to true when first score = 10', function() {
spyOn(Math, "random").and.returnValues(0.95, 0.5);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([10, 0]);
expect(frame.getStrike()).toBeTrue;
});
it('does not set strike to true when second roll is 10', function() {
spyOn(Math, "random").and.returnValues(0, 0.97);
frame.roll();
frame.roll();
expect(frame.getScore()).toEqual([0, 10]);
expect(frame.getStrike()).toBeFalse;
});
});
});
66 changes: 34 additions & 32 deletions spec/GameSpec.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
'use strict';

describe('Game', function() {
var game;
beforeEach(function() {
game = new Game();
var game;
beforeEach(function() {
game = new Game();
});
describe('getScoreCard', function() {
it('returns each frame that has been started', function() {
for (var i = 0; i < 6; i++) {
game.play();
}
expect(game.getScoreCard().length).toEqual(6);
});
describe('getScoreCard', function() {
it('returns each frame that has been started', function() {
for (var i = 0; i < 6; i++) {
game.play();
}
expect(game.getScoreCard().length).toEqual(6);
});
xit('returns both rolls for each frame', function() {
for (var i = 0; i < 6; i++) {
game.play();
}
expect(game.getScoreCard()[1].length).toEqual(2);
});
xit('returns both rolls for each frame', function() {
for (var i = 0; i < 6; i++) {
game.play();
}
expect(game.getScoreCard()[1].length).toEqual(2);
});
describe('play', function() {
it('rolls a ball and updates the frame score', function() {
spyOn(Math, "random").and.returnValue(0.5);
game.play();
expect(game.getScoreCard()).toEqual([[5]]);
});
});
describe('play', function() {
it('rolls a ball and updates the frame score', function() {
spyOn(Math, "random").and.returnValue(0.5);
game.play();
expect(game.getScoreCard()).toEqual([
[5]
]);
});
describe('getTotalScore', function() {
it('returns total score', function() {
spyOn(Math, "random").and.returnValues(0.5, 0.9, 0.1, 0.5);
for (var i = 0; i < 5; i++) {
game.play();
console.log(game.getScoreCard()[i]);
}
expect(game.getTotalScore()).toEqual( );
});
});
describe('getTotalScore', function() {
it('returns total score', function() {
spyOn(Math, "random").and.returnValues(0.5, 0.9, 0.1, 0.5);
for (var i = 0; i < 5; i++) {
game.play();
console.log(game.getScoreCard()[i]);
}
expect(game.getTotalScore()).toEqual();
});
});

});
});
40 changes: 20 additions & 20 deletions spec/RollSpec.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';

describe('Roll', function() {
var roll;
beforeEach(function() {
roll = new Roll();
});
describe('randomInt', function() {
it('returns random number between 0 and the remaining pins for a frame',
function () {
expect(roll.randomInt(10)).toBeLessThan(11);
expect(roll.randomInt(7)).toBeLessThan(8);
expect(roll.randomInt(5)).toBeLessThan(6);
expect(roll.randomInt(2)).toBeLessThan(3);
});
});
describe('score', function() {
it('returns random number between 0 and the remaining pins for a frame',
function () {
expect(roll.score(10)).toBeLessThan(11);
});
});
});
var roll;
beforeEach(function() {
roll = new Roll();
});
describe('randomInt', function() {
it('returns random number between 0 and the remaining pins for a frame',
function() {
expect(roll.randomInt(10)).toBeLessThan(11);
expect(roll.randomInt(7)).toBeLessThan(8);
expect(roll.randomInt(5)).toBeLessThan(6);
expect(roll.randomInt(2)).toBeLessThan(3);
});
});
describe('score', function() {
it('returns random number between 0 and the remaining pins for a frame',
function() {
expect(roll.score(10)).toBeLessThan(11);
});
});
});
37 changes: 18 additions & 19 deletions src/Frame.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
'use strict';

function Frame() {
this.score = [];
this.score = [];
}

Frame.prototype.roll = function() {
if (this.rollCount() <= 1 && this.remainder() > 0) {
var roll = new Roll().score(this.remainder());
this.updateScore(roll);
} else if (this.rollCount() <= 1) {
this.updateScore(0);
}
this.checkEnd();
if (this.rollCount() <= 1 && this.remainder() > 0) {
var roll = new Roll().score(this.remainder());
this.updateScore(roll);
} else if (this.rollCount() <= 1) {
this.updateScore(0);
}
this.checkEnd();
};

Frame.prototype.rollCount = function() {
return this.getScore().length;
return this.getScore().length;
};

Frame.prototype.checkEnd = function() {
if (this.rollCount() === 2) {
scoreCard.updateFrames(this.getScore());
}
if (this.rollCount() === 2) {
scoreCard.updateFrames(this.getScore());
}
};

Frame.prototype.getScore = function() {
return this.score;
return this.score;
};

Frame.prototype.updateScore = function(rollScore) {
this.score.push(rollScore);
this.score.push(rollScore);
};

Frame.prototype.remainder = function() {
if (this.rollCount() > 0) {
return 10 - this.score[0];
}
return 10;
if (this.rollCount() > 0) {
return 10 - this.score[0];
}
return 10;
};

Loading

0 comments on commit d160783

Please sign in to comment.