forked from makersacademy/bowling-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jasmine node totest through command line; Added ESLint: Ran bea…
…utifier with new rules on all files
- Loading branch information
Sam
authored and
Sam
committed
Jul 8, 2017
1 parent
4f5b560
commit d160783
Showing
10 changed files
with
179 additions
and
167 deletions.
There are no files selected for viewing
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
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
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
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
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; | ||
}); | ||
}); | ||
}); |
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
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(); | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
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
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); | ||
}); | ||
}); | ||
}); |
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
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; | ||
}; | ||
|
Oops, something went wrong.