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.
Significant refactor and added new unit tests; Need to complete unit …
…testing and fix feature test;
- Loading branch information
Sam
authored and
Sam
committed
Jul 9, 2017
1 parent
f721eda
commit fb8671b
Showing
12 changed files
with
313 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
describe('Play a frame', function () { | ||
it('updates the scorecard with correct frame scores', function () { | ||
var game, scorecard; | ||
game = new Game(); | ||
spyOn(Math, 'random').and.returnValues(0.51, 0.9); | ||
game.play(); | ||
game.play(); | ||
scorecard = game.getScoreCard(); | ||
console.dir(scorecard.getCard()); | ||
expect(scorecard.getCard()).toEqual([[5, 5]]); | ||
}); | ||
}); |
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,67 @@ | ||
'use strict'; | ||
|
||
describe('Frame', function() { | ||
describe('Frame', function () { | ||
var frame; | ||
beforeEach(function() { | ||
|
||
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('processRoll', function () { | ||
it('calls checkFullFrame', function () { | ||
spyOn(frame, 'checkFullFrame'); | ||
frame.processRoll(); | ||
expect(frame.checkFullFrame).toHaveBeenCalled(); | ||
}); | ||
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('calls updateFrameScore and passes roll() if rollcount is less than 2 and remainder greater than 0', function () { | ||
spyOn(frame, 'getRollCount'); | ||
frame.getRollCount.and.returnValue(1); | ||
spyOn(frame, 'remainder'); | ||
frame.remainder.and.returnValue(10); | ||
spyOn(Math, 'random').and.returnValue(0.51); | ||
spyOn(frame, 'updateFrameScore'); | ||
frame.processRoll(); | ||
expect(frame.updateFrameScore).toHaveBeenCalledWith(5); | ||
}); | ||
}); | ||
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('calls updateFrameScore and passes 0 if rollcount is less than 2 but remainder is 0', function () { | ||
spyOn(frame, 'getRollCount'); | ||
frame.getRollCount.and.returnValue(1); | ||
spyOn(frame, 'remainder'); | ||
frame.remainder.and.returnValue(0); | ||
spyOn(frame, 'updateFrameScore'); | ||
frame.processRoll(); | ||
expect(frame.updateFrameScore).toHaveBeenCalledWith(0); | ||
}); | ||
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; | ||
it('does not call updateFrameScore if rollcount is >= 2', function () { | ||
spyOn(frame, 'getRollCount'); | ||
frame.getRollCount.and.returnValue(2); | ||
spyOn(frame, 'remainder'); | ||
frame.remainder.and.returnValue(5); | ||
spyOn(frame, 'updateFrameScore'); | ||
frame.processRoll(); | ||
expect(frame.updateFrameScore).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
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; | ||
|
||
describe('getRollCount', function () { | ||
it('returns rollCount', function () { | ||
frame.rollCount = 4; | ||
expect(frame.getRollCount()).toEqual(4); | ||
}); | ||
}); | ||
|
||
describe('remainder', function () { | ||
it('defaults to return 10 if no roll has been taken', function () { | ||
spyOn(frame, 'getRollCount'); | ||
frame.getRollCount.and.returnValue(0); | ||
expect(frame.remainder()).toEqual(10); | ||
}); | ||
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('returns points left after a roll has been taken', function () { | ||
spyOn(frame, 'getRollCount'); | ||
frame.getRollCount.and.returnValue(1); | ||
spyOn(frame, 'getFrameScore'); | ||
frame.getFrameScore.and.returnValue([4]); | ||
expect(frame.remainder()).toEqual(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,71 @@ | ||
'use strict'; | ||
|
||
describe('Game', function () { | ||
var game; | ||
var game, frame; | ||
|
||
beforeEach(function () { | ||
game = new Game(); | ||
frame = game.currentFrame; | ||
}); | ||
|
||
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); | ||
describe('play', function () { | ||
it('calls processroll on currentFrame', function () { | ||
spyOn(frame, 'processRoll'); | ||
game.play(); | ||
expect(frame.processRoll).toHaveBeenCalled(); | ||
}); | ||
it('calls nextFrame', function () { | ||
spyOn(game, 'nextFrame'); | ||
game.play(); | ||
expect(game.nextFrame).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
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('getCurrentFrame', function () { | ||
it('returns a frame object', function () { | ||
expect(frame instanceof Frame).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('startNewFrame', function () { | ||
it('updates currentFrame with new Frame instance', function () { | ||
game.startNewFrame(); | ||
var newFrame = game.getCurrentFrame(); | ||
expect(frame).not.toBe(newFrame); | ||
}); | ||
}); | ||
|
||
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('nextFrame', function () { | ||
beforeEach(function () { | ||
spyOn(game, 'isFrameFinished'); | ||
spyOn(game, 'startNewFrame'); | ||
}); | ||
it('calls startNewFrame if isFrameFinished returns true', function () { | ||
game.isFrameFinished.and.returnValue(true); | ||
game.nextFrame(); | ||
expect(game.isFrameFinished).toHaveBeenCalled(); | ||
expect(game.startNewFrame).toHaveBeenCalled(); | ||
}); | ||
it('does not call startNewFrame if isFrameFinished returns false', function () { | ||
game.isFrameFinished.and.returnValue(false); | ||
game.nextFrame(); | ||
expect(game.isFrameFinished).toHaveBeenCalled(); | ||
expect(game.startNewFrame).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('isFrameFinished', function () { | ||
it('calls getIsFinished on currentFrame', function () { | ||
spyOn(frame, 'getIsFinished'); | ||
game.isFrameFinished(); | ||
expect(frame.getIsFinished).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('getScoreCard', function () { | ||
it('returns a frame object', function () { | ||
var card = game.getScoreCard(); | ||
expect(card instanceof ScoreCard).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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,25 +1,18 @@ | ||
'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', | ||
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); | ||
expect(randomInt(10)).toBeLessThan(11); | ||
expect(randomInt(7)).toBeLessThan(8); | ||
expect(randomInt(5)).toBeLessThan(6); | ||
expect(randomInt(2)).toBeLessThan(3); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('score', function () { | ||
it('returns random number between 0 and the remaining pins for a frame', | ||
describe('roll', function () { | ||
it('returns random number between 0 and the remaining pins for a frame', | ||
function () { | ||
expect(roll.score(10)).toBeLessThan(11); | ||
expect(roll(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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
describe('ScoreCard', function () { | ||
var card; | ||
|
||
beforeEach(function () { | ||
card = new ScoreCard(); | ||
}); | ||
|
||
describe('getCard', function () { | ||
it('returns an array', function () { | ||
expect(card.getCard()).toEqual(jasmine.any(Array)); | ||
}); | ||
it('returns array of arrays stored in this.card', function () { | ||
card.card = [[1, 1], [5, 0]]; | ||
expect(card.getCard()).toEqual([[1, 1], [5, 0]]); | ||
}); | ||
}); | ||
|
||
describe('updateCard', function () { | ||
beforeEach(function () { | ||
spyOn(card, 'isFullFrame'); | ||
}); | ||
it('checks if frame is full', function () { | ||
card.updateCard(1); | ||
expect(card.isFullFrame).toHaveBeenCalled(); | ||
}); | ||
it('updates complete frame with new rollScore', function () { | ||
spyOn(card, 'getLastFrame'); | ||
card.getLastFrame.and.returnValue([1]); | ||
card.isFullFrame.and.returnValue(false); | ||
card.updateCard(2); | ||
expect(card.getLastFrame).toHaveBeenCalled(); | ||
expect(card.getLastFrame()).toEqual([1, 2]); | ||
}); | ||
it('pushes new frame if last frame has 2 objects', function () { | ||
spyOn(card, 'getLastFrame').and.callThrough(); | ||
card.isFullFrame.and.returnValue(true); | ||
card.updateCard(2); | ||
expect(card.getLastFrame).not.toHaveBeenCalled(); | ||
expect(card.getLastFrame()).toEqual([2]); | ||
expect(card.getCard()).toEqual([[], [2]]); | ||
}); | ||
}); | ||
|
||
describe('getLastFrame', function () { | ||
it('returns last item in this.card as an array', function () { | ||
card.card = [[1, 1], [5, 0]]; | ||
expect(card.getLastFrame()).toEqual([5, 0]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.