Skip to content

Commit 00f543d

Browse files
committed
Adding tests for "Sudoku validator".
1 parent c89a83d commit 00f543d

File tree

10 files changed

+178
-0
lines changed

10 files changed

+178
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Tests for "Sum of spiral's diagonals".
1919
- Tests for "Brackets, extreme edition".
2020
- Tests for "The electrician apprentice".
21+
- Tests for "Sudoku validator".
2122

2223
## [1.6.0] - 2022-03-11
2324
### Added
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "Sudoku validator" puzzle.
3+
*/
4+
function execute(readline) {
5+
for (let i = 0; i < 9; i++) {
6+
var inputs = readline().split(' ');
7+
for (let j = 0; j < 9; j++) {
8+
const n = parseInt(inputs[j]);
9+
}
10+
}
11+
12+
// Write an answer using console.log()
13+
// To debug: console.error('Debug messages...');
14+
15+
console.log('true or false');
16+
}
17+
18+
export { execute };
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/sudokuValidator/sudokuValidator.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Sudoku validator", 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("Basic grid", function() {
21+
let inputFile = new File(__dirname + 'input/01 - basic grid.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"true"
28+
);
29+
});
30+
31+
test("Another correct grid", function() {
32+
let inputFile = new File(__dirname + 'input/02 - another correct grid.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"true"
39+
);
40+
});
41+
42+
test("Row error", function() {
43+
let inputFile = new File(__dirname + 'input/03 - row error.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"false"
50+
);
51+
});
52+
53+
test("Column error", function() {
54+
let inputFile = new File(__dirname + 'input/04 - column error.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"false"
61+
);
62+
});
63+
64+
test("Subgrid error", function() {
65+
let inputFile = new File(__dirname + 'input/05 - subgrid error.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"false"
72+
);
73+
});
74+
75+
test("Rubbish error", function() {
76+
let inputFile = new File(__dirname + 'input/06 - rubbish error.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
"false"
83+
);
84+
});
85+
86+
test("When summing is not enough", function() {
87+
let inputFile = new File(__dirname + 'input/07 - when summing is not enough.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
"false"
94+
);
95+
});
96+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1 2 3 4 5 6 7 8 9
2+
4 5 6 7 8 9 1 2 3
3+
7 8 9 1 2 3 4 5 6
4+
9 1 2 3 4 5 6 7 8
5+
3 4 5 6 7 8 9 1 2
6+
6 7 8 9 1 2 3 4 5
7+
8 9 1 2 3 4 5 6 7
8+
2 3 4 5 6 7 8 9 1
9+
5 6 7 8 9 1 2 3 4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 2 2 6 9 7 8 1
2+
6 8 5 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
1 9 7 8 3 4 5 6 2
4+
8 2 6 1 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
1 5 9 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4 3 5 2 6 9 7 8 1
2+
6 8 2 5 7 1 4 9 3
3+
8 9 7 1 3 4 5 6 2
4+
1 2 6 8 9 5 3 4 7
5+
3 7 4 6 8 2 9 1 5
6+
9 5 1 7 4 3 6 2 8
7+
5 1 9 3 2 6 8 7 4
8+
2 4 8 9 5 7 1 3 6
9+
7 6 3 4 1 8 2 5 9
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
5 9 6 1 4 2 5 3 7
2+
6 1 4 3 5 8 2 4 8
3+
5 6 9 4 1 2 5 3 6
4+
1 9 5 3 6 8 4 1 6
5+
5 9 3 6 3 4 8 2 1
6+
5 9 5 3 2 1 4 5 6
7+
1 3 6 4 8 6 5 2 5
8+
4 1 2 3 6 8 4 9 2
9+
3 6 8 7 4 1 5 6 3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1 3 3 4 5 6 7 7 9
2+
4 5 6 7 7 9 1 3 3
3+
7 7 9 1 3 3 4 5 6
4+
9 1 3 3 4 5 6 7 7
5+
3 4 5 6 7 7 9 1 3
6+
6 7 7 9 1 3 3 4 5
7+
7 9 1 3 3 4 5 6 7
8+
3 3 4 5 6 7 7 9 1
9+
5 6 7 7 9 1 3 3 4

0 commit comments

Comments
 (0)