-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (63 loc) · 1.58 KB
/
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
const assert = require('assert').strict;
const { score, parse } = require('./index.js');
describe('Bowling Game', () => {
let expected;
let actual;
context('all gutter balls', () => {
beforeEach(() => {
expected = 0;
actual = score(Array(20).fill(0));
});
it('scores 0', () => {
assert.equal(actual, expected);
});
});
context('all ones', () => {
beforeEach(() => {
expected = 20;
actual = score(Array(20).fill(1));
});
it('scores 20', () => {
assert.equal(actual, expected);
});
});
context('one spare', () => {
beforeEach(() => {
expected = 16;
actual = score([5, 5, 3, ...Array(17).fill(0)]);
});
it('scores 16', () => {
assert.equal(actual, expected);
});
});
context('one strike', () => {
beforeEach(() => {
expected = 24;
actual = score([10, 3, 4, ...Array(16).fill(0)]);
});
it('scores 24', () => {
assert.equal(actual, expected);
});
});
context('perfect game', () => {
beforeEach(() => {
expected = 300;
actual = score(Array(12).fill(10));
});
it('scores 300', () => {
assert.equal(actual, expected);
});
});
context('parsing string input', () => {
beforeEach(() => {
expected = [1, 6, 5, 5, 2, 5, 1, 9, 10, 2, 8, 7, 1, 10, 10, 1, 9, 7];
actual = parse('165/251/X2/71XX1/7');
});
it('transforms a string into an array of numbers', () => {
assert.deepEqual(actual, expected);
});
it('scores 149', () => {
assert.equal(score(actual), 149);
});
});
});