Skip to content

Commit 0fe33be

Browse files
committed
Adding tests for "Sum of spiral's diagonals".
1 parent 7e490ff commit 0fe33be

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Tests for "7-segment scanner".
1616
- Tests for "Lumen".
1717
- Tests for "A child's play".
18+
- Tests for "Sum of spiral's diagonals".
1819

1920
## [1.6.0] - 2022-03-11
2021
### Added
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* The "Sum of spiral's diagonals" puzzle.
3+
*/
4+
function execute(readline) {
5+
const n = parseInt(readline());
6+
7+
// Write an answer using console.log()
8+
// To debug: console.error('Debug messages...');
9+
10+
console.log('answer');
11+
}
12+
13+
export { execute };
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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/sumOfSpiralsDiagonals/sumOfSpiralsDiagonals.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Sum of spiral's diagonals", 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('Odd spiral', function() {
22+
let inputFile = new File(__dirname + 'input/01 - odd spiral.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
133
29+
);
30+
});
31+
32+
test('Even spiral', function() {
33+
let inputFile = new File(__dirname + 'input/02 - even spiral.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
61584
40+
);
41+
});
42+
43+
test('Bigger spiral', function() {
44+
let inputFile = new File(__dirname + 'input/03 - bigger spiral.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
270890816
51+
);
52+
});
53+
54+
test('Milky spiral', function() {
55+
let inputFile = new File(__dirname + 'input/04 - milky spiral.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
4086949725
62+
);
63+
});
64+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
36
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
588
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1453

0 commit comments

Comments
 (0)