Skip to content

Commit 21d8a8f

Browse files
committed
Adding tests for "Is the king in check? (part 1)".
1 parent a31be0f commit 21d8a8f

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Tests for "Add'em up".
3232
- Tests for "Rotating arrows".
3333
- Tests for "10 pin bowling scores".
34+
- Tests for "Is the king in check? (part 1)".
3435

3536
### Fixed
3637
- File import for "A child's play".
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The "Is the king in check? (part 1)" puzzle.
3+
*/
4+
function execute(readline) {
5+
for (let i = 0; i < 8; i++) {
6+
const chessRow = readline();
7+
}
8+
9+
// Write an answer using console.log()
10+
// To debug: console.error('Debug messages...');
11+
12+
console.log('Check/No Check');
13+
}
14+
15+
export { execute };
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/isTheKingInCheckPart1/isTheKingInCheckPart1.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Is the king in check? (part 1)", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("R vs K", function() {
21+
let inputFile = new File(__dirname + 'input/01 - R vs K.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"Check"
28+
);
29+
});
30+
31+
test("B vs K", function() {
32+
let inputFile = new File(__dirname + 'input/02 - B vs K.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"No Check"
39+
);
40+
});
41+
42+
test("Q vs K", function() {
43+
let inputFile = new File(__dirname + 'input/03 - Q vs K.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"Check"
50+
);
51+
});
52+
53+
test("N vs K", function() {
54+
let inputFile = new File(__dirname + 'input/04 - N vs K.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"No Check"
61+
);
62+
});
63+
64+
test("Test 5", function() {
65+
let inputFile = new File(__dirname + 'input/05 - test 5.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"Check"
72+
);
73+
});
74+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ R _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ K _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ K _ _ _ _ _
5+
_ _ B _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Q _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ K _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ N _ K _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ _ _ _
8+
_ _ _ _ _ _ _ _
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_ _ _ _ _ _ _ _
2+
_ _ _ _ _ _ _ _
3+
_ _ _ _ _ _ _ _
4+
_ _ _ _ _ _ _ _
5+
_ _ _ _ _ _ _ _
6+
_ _ _ _ _ _ _ _
7+
_ _ _ _ _ N _ _
8+
_ _ _ _ _ _ _ K

0 commit comments

Comments
 (0)