Skip to content

Commit e681e38

Browse files
committed
Adding tests for "Binary image".
1 parent a3ff08f commit e681e38

File tree

16 files changed

+178
-0
lines changed

16 files changed

+178
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Tests for "Equivalent resistance, circuit building".
1313
- Tests for "1D spreadsheet".
1414
- Tests for "Ghost legs".
15+
- Tests for "Binary image".
1516

1617
### Changed
1718
- Using "__dirname" for input / output paths.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "Binary image" puzzle.
3+
*/
4+
function execute(readline) {
5+
const h = parseInt(readline());
6+
for (let i = 0; i < h; i++) {
7+
const row = readline();
8+
}
9+
for (let i = 0; i < h; i++) {
10+
11+
// Write an answer using console.log()
12+
// To debug: console.error('Debug messages...');
13+
14+
console.log('answer');
15+
}
16+
}
17+
18+
export { execute };
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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/binaryImage/binaryImage.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
/**
10+
* Tests for the "Binary image" puzzle.
11+
*/
12+
suite('Binary image', 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('Vertical stripes', function() {
25+
let inputFile = new File(__dirname + 'input/01 - vertical stripes.txt');
26+
27+
execute(inputFile.readline.bind(inputFile));
28+
29+
assertOutputAnswer(__dirname + 'output/01 - vertical stripes.txt');
30+
});
31+
32+
test('Starting by 0', function() {
33+
let inputFile = new File(__dirname + 'input/02 - starting by 0.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assertOutputAnswer(__dirname + 'output/02 - starting by 0.txt');
38+
});
39+
40+
test('Chess board', function() {
41+
let inputFile = new File(__dirname + 'input/03 - chess board.txt');
42+
43+
execute(inputFile.readline.bind(inputFile));
44+
45+
assertOutputAnswer(__dirname + 'output/03 - chess board.txt');
46+
});
47+
48+
test('Horizontal stripes', function() {
49+
let inputFile = new File(__dirname + 'input/04 - horizontal stripes.txt');
50+
51+
execute(inputFile.readline.bind(inputFile));
52+
53+
assertOutputAnswer(__dirname + 'output/04 - horizontal stripes.txt');
54+
});
55+
56+
test('Codingame', function() {
57+
let inputFile = new File(__dirname + 'input/05 - codingame.txt');
58+
59+
execute(inputFile.readline.bind(inputFile));
60+
61+
assertOutputAnswer(__dirname + 'output/05 - codingame.txt');
62+
});
63+
64+
test('Invalid', function() {
65+
let inputFile = new File(__dirname + 'input/06 - invalid.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"INVALID"
72+
);
73+
});
74+
75+
test('Random', function() {
76+
let inputFile = new File(__dirname + 'input/07 - random.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assertOutputAnswer(__dirname + 'output/07 - random.txt');
81+
});
82+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 3 2 1
3+
1 3 2 1
4+
1 3 2 1
5+
1 3 2 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
0 1 1 1 1
3+
0 1 1 1 1
4+
0 1 1 1 1
5+
0 1 1 1 1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
0 1 1 1 1 1 1 1 1
3+
1 1 1 1 1 1 1 1
4+
0 1 1 1 1 1 1 1 1
5+
1 1 1 1 1 1 1 1
6+
0 1 1 1 1 1 1 1 1
7+
1 1 1 1 1 1 1 1
8+
0 1 1 1 1 1 1 1 1
9+
1 1 1 1 1 1 1 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
8
3+
0 8
4+
8
5+
0 8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
45
3+
2 2 3 2 2 3 2 1 1 1 3 1 2 2 3 2 2 1 3 1 1 4 1
4+
1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 2 1 2 1 1 4
5+
1 1 4 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 4 1 2 1 1 1 1 1 1 1 1 3 2
6+
1 1 4 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 4 1 1 3 1 1 1 4
7+
1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 3 1 1 1 2 1 1 1 2 1 1 1 3 1 1 1 4
8+
2 2 3 2 2 3 2 1 1 1 3 1 2 2 2 1 2 1 1 1 3 1 1 4 1
9+
45
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
0 1 1 2
3+
0 2 1 1
4+
0 1 1 1
5+
1 1 1 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
0 1 2 1 1 1 2 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 3 1 2
3+
2 3 1 1 6 1 1 1 1 1 2 2 2 1 1 1 4 1 1 1 3 2 1 2 1 1 1 1 3 1
4+
1 1 3 5 2 3 1 2 1 3 2 2 2 3 1 2 4 2 4 5 1
5+
0 1 1 1 1 3 3 1 1 2 2 2 2 1 1 3 1 1 2 1 1 2 2 1 3 1 1 1 2 4 1 1
6+
2 2 1 1 1 3 1 1 2 1 6 1 1 4 1 1 2 1 1 1 1 1 1 1 2 2 3 1 4

0 commit comments

Comments
 (0)