Skip to content

Commit 05a9f12

Browse files
committed
Adding tests for "ISBN check digit".
1 parent af6fcee commit 05a9f12

File tree

11 files changed

+451
-0
lines changed

11 files changed

+451
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Tests for "Walk on a die".
1010
- Tests for "Dolbear's law".
11+
- Tests for "ISBN check digit".
1112

1213
### Changed
1314
- Using "__dirname" for input / output paths.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The "ISBN check digit" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
const ISBN = readline();
8+
}
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
console.log('answer');
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/ISBNCheckDigit/ISBNCheckDigit.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
/**
10+
* Tests for the "ISBN check digit" puzzle.
11+
*/
12+
suite('ISBN check digit', function() {
13+
const sandbox = sinon.createSandbox();
14+
15+
setup(function () {
16+
sandbox.stub(console, "log");
17+
});
18+
19+
teardown(function () {
20+
sandbox.restore();
21+
});
22+
23+
24+
test('Example', function() {
25+
let inputFile = new File(__dirname + 'input/01 - example.txt');
26+
27+
execute(inputFile.readline.bind(inputFile));
28+
29+
assertOutputAnswer(__dirname + 'output/01 - example.txt');
30+
});
31+
32+
test('Short', function() {
33+
let inputFile = new File(__dirname + 'input/02 - short.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assertOutputAnswer(__dirname + 'output/02 - short.txt');
38+
});
39+
40+
test('Longer', function() {
41+
let inputFile = new File(__dirname + 'input/03 - longer.txt');
42+
43+
execute(inputFile.readline.bind(inputFile));
44+
45+
assertOutputAnswer(__dirname + 'output/03 - longer.txt');
46+
});
47+
48+
test('Much longer', function() {
49+
let inputFile = new File(__dirname + 'input/04 - much longer.txt');
50+
51+
execute(inputFile.readline.bind(inputFile));
52+
53+
assertOutputAnswer(__dirname + 'output/04 - much longer.txt');
54+
});
55+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
0306406152
3+
013603599X
4+
1145185215X
5+
9780306406157
6+
9780306406154
7+
978043551907X
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10
2+
0470371722
3+
9781119247792
4+
9780470124512
5+
11190495550
6+
1118105354
7+
9781118737637
8+
0387372350
9+
154875155X
10+
9781548751555
11+
978193981677
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
21
2+
0471697037
3+
1171711743
4+
1146386265
5+
9781531807382
6+
0671039414
7+
0553282964
8+
0743412524
9+
Im_garbage
10+
0553270502
11+
9781784399092
12+
0553493825
13+
9781511343572
14+
0553156284
15+
0553570099
16+
9780606393188
17+
97804X8458533
18+
9780745669779
19+
0976315262
20+
1498773192
21+
9780408478999
22+
9780691154305

0 commit comments

Comments
 (0)