forked from makersacademy/bowling-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreCard.test.js
43 lines (36 loc) · 1.22 KB
/
scoreCard.test.js
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
const ScoreCard = require('./scoreCard');
describe('ScoreCard', () => {
let myScore;
beforeEach(() => {
myScore = new ScoreCard();
});
it('adds a score to each frame', () => {
myScore.addFrame(2, 5);
expect(myScore.frames[0].firstRoll).toEqual(2);
expect(myScore.frames[0].secondRoll).toEqual(5);
});
it('initialises a score of zero by default when no frames have been played', () => {
expect(myScore.calculateScore()).toBe(0);
});
it('calculates the score without any strikes or spares', () => {
myScore.addFrame(3, 2);
myScore.addFrame(2, 5);
expect(myScore.calculateScore()).toBe(12);
});
it('calculates the score with bonus points for strikes', () => {
myScore.addFrame(10, 0);
myScore.addFrame(7, 2);
expect(myScore.calculateScore()).toBe(10 + 7 + 2 + 7 + 2);
});
it('calculates the score with bonus points for spares', () => {
myScore.addFrame(5, 5);
myScore.addFrame(4, 4);
expect(myScore.calculateScore()).toBe(5 + 5 + 4 + 4 + 4);
});
it('calculates the score correctly for a perfect game with bonus frames', () => {
for (let i = 0; i < 12; i++) {
myScore.addFrame(10, 0);
}
expect(myScore.calculateScore()).toBe(300);
});
});