Skip to content

Commit a31be0f

Browse files
committed
Adding tests for "10 pin bowling scores".
1 parent b97f121 commit a31be0f

File tree

10 files changed

+107
-0
lines changed

10 files changed

+107
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Tests for "Darts".
3131
- Tests for "Add'em up".
3232
- Tests for "Rotating arrows".
33+
- Tests for "10 pin bowling scores".
3334

3435
### Fixed
3536
- File import for "A child's play".
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The "10 pin bowling scores" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
const GAME = readline();
8+
}
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
console.log('5 13 18 26 31 32 34 40 47 54');
14+
}
15+
16+
export { execute };
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { assertOutputAnswer } from '../../../../assertOutputAnswer.js';
5+
import { execute } from '../../../../../lib/community/training/easy/tenPinBowlingScores/tenPinBowlingScores.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("10 pin bowling scores", function() {
10+
const sandbox = sinon.createSandbox();
11+
12+
setup(function () {
13+
sandbox.stub(console, "log");
14+
});
15+
16+
teardown(function () {
17+
sandbox.restore();
18+
});
19+
20+
21+
test("No strikes no spares", function() {
22+
let inputFile = new File(__dirname + 'input/01 - no strikes no spares.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
"5 13 18 26 31 32 34 40 47 54"
29+
);
30+
});
31+
32+
test("Spares", function() {
33+
let inputFile = new File(__dirname + 'input/02 - spares.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assertOutputAnswer(__dirname + 'output/02 - spares.txt');
38+
});
39+
40+
test("Strikes", function() {
41+
let inputFile = new File(__dirname + 'input/03 - strikes.txt');
42+
43+
execute(inputFile.readline.bind(inputFile));
44+
45+
assertOutputAnswer(__dirname + 'output/03 - strikes.txt');
46+
});
47+
48+
test("Strikes and spares", function() {
49+
let inputFile = new File(__dirname + 'input/04 - strikes and spares.txt');
50+
51+
execute(inputFile.readline.bind(inputFile));
52+
53+
assertOutputAnswer(__dirname + 'output/04 - strikes and spares.txt');
54+
});
55+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
32 71 23 44 5- 1- 11 15 16 7-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
32 7/ 6/ 3/ 11 9/ 1- 1/ 2/ 5-
3+
-/ 5- 52 52 72 71 1/ 51 3/ 3/-
4+
7/ -/ 5/ 72 7/ 22 6/ -7 7/ --
5+
44 1/ 2/ -/ -9 81 2/ 12 7/ 5/6
6+
1/ 1/ 5/ 2/ 3/ 5/ 5/ -/ 5/ 16
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
X 5/ X 5/ 8/ 63 7/ -/ 8/ 61
3+
3- 6/ X 5/ 9/ X 3/ 7/ 6/ -/9
4+
X X X 1/ 5/ X 8/ 36 3/ XX6
5+
7/ 7- X 7/ X 2/ X 8/ 9- 61
6+
X 7/ 9- 3/ 8/ 5/ X 52 X 5/8
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
X X X X X X X X X XXX
3+
X X X X X -/ X 4/ X 4/8
4+
X X X -/ X X X X X 8/5
5+
X X 7/ X X X X X -/ -/6
6+
X X X X X X X X X 2/X
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
5 21 34 45 47 58 59 71 86 91
2+
15 20 27 34 43 51 66 72 85 95
3+
10 25 42 51 63 67 77 84 94 94
4+
8 20 30 40 49 58 69 72 87 103
5+
11 26 38 51 66 81 91 106 117 124
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
20 40 60 78 94 103 113 131 147 154
2+
3 23 43 62 82 102 119 135 145 164
3+
30 51 71 86 106 126 139 148 168 194
4+
17 24 44 64 84 104 124 143 152 159
5+
20 39 48 66 81 101 118 125 145 163
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
30 60 90 120 150 180 210 240 270 300
2+
30 60 90 110 130 150 170 190 210 228
3+
30 50 70 90 120 150 180 208 228 243
4+
27 47 67 97 127 157 177 197 207 223
5+
30 60 90 120 150 180 210 232 252 272

0 commit comments

Comments
 (0)