Skip to content

Commit 49699de

Browse files
committed
Adding tests for "Snail run".
1 parent 279a21f commit 49699de

File tree

11 files changed

+209
-0
lines changed

11 files changed

+209
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Tests for "Simple load balancing".
3333
- Tests for "Are the clumps normal".
3434
- Tests for "Bulk email generator".
35+
- Tests for "Snail run".
3536

3637
### Changed
3738
- Docker Node image from "14.16.1-alpine" to "node:16.14.2-alpine".
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* The "Snail run" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/snail-run}
4+
*/
5+
function execute(readline) {
6+
const numberSnails = parseInt(readline());
7+
for (let i = 0; i < numberSnails; i++) {
8+
const speedSnail = parseInt(readline());
9+
}
10+
const mapHeight = parseInt(readline());
11+
const mapWidth = parseInt(readline());
12+
for (let i = 0; i < mapHeight; i++) {
13+
const ROW = readline();
14+
}
15+
16+
// Write an answer using console.log()
17+
// To debug: console.error('Debug messages...');
18+
19+
console.log('winner is number');
20+
}
21+
22+
export { execute };
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/snailRun/snailRun.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Snail run", 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("Simple run", function() {
21+
let inputFile = new File(__dirname + 'input/01 - simple run.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
3
28+
);
29+
});
30+
31+
test("Run in progress", function() {
32+
let inputFile = new File(__dirname + 'input/02 - run in progress.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
3
39+
);
40+
});
41+
42+
test("Only one arrives", function() {
43+
let inputFile = new File(__dirname + 'input/03 - only one arrives.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
1
50+
);
51+
});
52+
53+
test("In a mess", function() {
54+
let inputFile = new File(__dirname + 'input/04 - in a mess.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
3
61+
);
62+
});
63+
64+
test("Conversely", function() {
65+
let inputFile = new File(__dirname + 'input/05 - conversely.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
3
72+
);
73+
});
74+
75+
test("Difficult 1", function() {
76+
let inputFile = new File(__dirname + 'input/06 - difficult 1.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
3
83+
);
84+
});
85+
86+
test("Difficult 2", function() {
87+
let inputFile = new File(__dirname + 'input/07 - difficult 2.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
3
94+
);
95+
});
96+
97+
test("Difficult 3", function() {
98+
let inputFile = new File(__dirname + 'input/08 - difficult 3.txt');
99+
100+
execute(inputFile.readline.bind(inputFile));
101+
102+
assert.strictEqual(
103+
console.log.getCall(0).args[0],
104+
2
105+
);
106+
});
107+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
2
3+
3
4+
5
5+
3
6+
6
7+
1****#
8+
2****#
9+
3****#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
4
2+
1
3+
3
4+
4
5+
1
6+
4
7+
6
8+
**1**#
9+
*2***#
10+
**3**#
11+
**4**#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
3
3+
1
4+
2
5+
3
6+
8
7+
1*******
8+
2******#
9+
3*******
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
4
3+
2
4+
2
5+
3
6+
7
7+
12****3
8+
*******
9+
******#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
5
2+
1
3+
1
4+
2
5+
1
6+
1
7+
5
8+
7
9+
#*****1
10+
#*****2
11+
#*****3
12+
#*****4
13+
#*****5
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
1
3+
1
4+
1
5+
3
6+
7
7+
**3****
8+
****2**
9+
#*****1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
4
2+
1
3+
1
4+
1
5+
1
6+
4
7+
7
8+
1******
9+
****3**
10+
**#***2
11+
******4

0 commit comments

Comments
 (0)