Skip to content

Commit 37e24d1

Browse files
committed
Adding tests for "Sandpile addition".
1 parent 1243e43 commit 37e24d1

19 files changed

+194
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Tests for "OneWay city".
3434
- Tests for "Plague, jr".
3535
- Tests for "English length units conversion".
36+
- Tests for "Sandpile addition".
3637

3738
## [1.14.0] - 2022-10-31
3839
### Added
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* The "Sandpile addition" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/sandpile-addition}
4+
*/
5+
function execute(readline) {
6+
const n = parseInt(readline());
7+
for (let i = 0; i < n; i++) {
8+
const row = readline();
9+
}
10+
for (let i = 0; i < n; i++) {
11+
const row = readline();
12+
}
13+
14+
// Write an answer using console.log()
15+
// To debug: console.error('Debug messages...');
16+
17+
console.log('answer');
18+
}
19+
20+
export { execute };
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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/medium/sandpileAddition/sandpileAddition.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Sandpile addition", 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("One simple addition", function() {
22+
let inputFile = new File(__dirname + 'input/01 - one simple addition.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assertOutputAnswer(__dirname + 'output/01 - one simple addition.txt');
27+
});
28+
29+
test("One more simple case", function() {
30+
let inputFile = new File(__dirname + 'input/02 - one more simple case.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assertOutputAnswer(__dirname + 'output/02 - one more simple case.txt');
35+
});
36+
37+
test("A lot of redistribution", function() {
38+
let inputFile = new File(__dirname + 'input/03 - a lot of redistribution.txt');
39+
40+
execute(inputFile.readline.bind(inputFile));
41+
42+
assertOutputAnswer(__dirname + 'output/03 - a lot of redistribution.txt');
43+
});
44+
45+
test("Pretty packed", function() {
46+
let inputFile = new File(__dirname + 'input/04 - pretty packed.txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assertOutputAnswer(__dirname + 'output/04 - pretty packed.txt');
51+
});
52+
53+
test("Two full sandpiles", function() {
54+
let inputFile = new File(__dirname + 'input/05 - two full sandpiles.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assertOutputAnswer(__dirname + 'output/05 - two full sandpiles.txt');
59+
});
60+
61+
test("Bigger grid", function() {
62+
let inputFile = new File(__dirname + 'input/06 - bigger grid.txt');
63+
64+
execute(inputFile.readline.bind(inputFile));
65+
66+
assertOutputAnswer(__dirname + 'output/06 - bigger grid.txt');
67+
});
68+
69+
test("Even bigger", function() {
70+
let inputFile = new File(__dirname + 'input/07 - even bigger.txt');
71+
72+
execute(inputFile.readline.bind(inputFile));
73+
74+
assertOutputAnswer(__dirname + 'output/07 - even bigger.txt');
75+
});
76+
77+
test("Asymmetric", function() {
78+
let inputFile = new File(__dirname + 'input/08 - asymmetric.txt');
79+
80+
execute(inputFile.readline.bind(inputFile));
81+
82+
assertOutputAnswer(__dirname + 'output/08 - asymmetric.txt');
83+
});
84+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
121
3+
202
4+
121
5+
020
6+
202
7+
020
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
301
3+
030
4+
103
5+
100
6+
010
7+
001
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
121
3+
232
4+
121
5+
303
6+
000
7+
303
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
333
3+
333
4+
333
5+
111
6+
111
7+
111
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
333
3+
333
4+
333
5+
333
6+
333
7+
333
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4
2+
3113
3+
1221
4+
1221
5+
3113
6+
1002
7+
0300
8+
0030
9+
2001
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
5
2+
31003
3+
13120
4+
01310
5+
02131
6+
30013
7+
11111
8+
12221
9+
12321
10+
12221
11+
11111

0 commit comments

Comments
 (0)