-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathframe.test.js
97 lines (83 loc) · 2.92 KB
/
frame.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
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
const Frame = require('./frame');
describe('Frame class unit test', () => {
describe('constructor', () => {
it('initliases with empty array this.rolls', () => {
frame = new Frame();
expect(frame.rolls).toEqual([]);
})
it('initliases with bonus points & regular points values of 0', () => {
frame = new Frame();
expect(frame.bonusPoints).toEqual(0);
expect(frame.regularPoints).toEqual(0);
})
});
describe('.roll', () => {
it('adds roll score to this.rolls', () => {
frame = new Frame();
frame.roll(5);
expect(frame.rolls[0]).toEqual(5);
expect(frame.rolls.length).toEqual(1);
frame.roll(5);
expect(frame.regularPoints).toEqual(10);
expect(frame.bonusPoints).toEqual(0);
});
it('refuses to add a roll if two have already been scored', () => {
expect(() => {
frame = new Frame();
frame.roll(5);
frame.roll(3);
frame.roll(6)
}).toThrow('Tried to add points to a frame that is already over');
});
it('refuses to add a roll if a strike was made on first roll=', () => {
frame = new Frame();
frame.roll(10);
expect(() => frame.roll(6)).toThrow('Tried to add points to a frame that is already over');
expect(frame.rolls).toEqual([10]);
});
it('returns error message given an invalid roll score', () => {
frame = new Frame();
expect(() => frame.roll(13)).toThrow('Tried to add an invalid roll score (13)');
expect(() => frame.roll(-5)).toThrow('Tried to add an invalid roll score (-5)');
});
it('returns error message if roll would exceed max score in a frame', () => {
frame = new Frame();
frame.roll(5);
expect(() => frame.roll(7)).toThrow('Tried to add roll that would exceed max score in a frame (5 + 7');
});
});
it('takes an array of points for .playFrame() and rolls for each one', () => {
frame = new Frame();
frame.playFrame([5, 3]);
expect(frame.regularPoints).toEqual(8)
});
describe('.isSpare()', () => {
it('returns true when frame is a spare', () => {
frame = new Frame();
frame.playFrame([5, 5]);
expect(frame.isSpare()).toEqual(true);
});
it('returns true when frame is a spare with a 10 on 2nd roll', () => {
frame = new Frame();
frame.playFrame([0, 10]);
expect(frame.isSpare()).toEqual(true);
});
it('returns false when frame is a strike', () => {
frame = new Frame();
frame.playFrame([10]);
expect(frame.isSpare()).toEqual(false);
});
});
describe('.isStrike()', () => {
it('returns true when frame is a strike', () => {
frame = new Frame();
frame.playFrame([10]);
expect(frame.isStrike()).toEqual(true);
});
it('returns false when frame is a spare', () => {
frame = new Frame();
frame.playFrame([2, 8]);
expect(frame.isStrike()).toEqual(false);
});
});
});