Skip to content

Commit f5f0ef5

Browse files
committed
Adding tests for "River crossing".
1 parent 68e4cab commit f5f0ef5

14 files changed

+126
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Fair numbering".
3737
- Tests for "A coin guessing game".
3838
- Tests for "Folding a note".
39+
- Tests for "River crossing".
3940

4041
## [1.11.0] - 2022-07-31
4142
### Added
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* The "River crossing" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/river-crossing}
4+
*/
5+
function execute(readline) {
6+
const INITIAL = readline();
7+
const TARGET = readline();
8+
9+
// Write an answer using console.log()
10+
11+
console.log('L L L L');
12+
console.log('R L R L');
13+
}
14+
15+
export { execute };
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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/riverCrossing/riverCrossing.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("River crossing", 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("The question is the solution", function() {
22+
let inputFile = new File(__dirname + 'input/01 - the question is the solution.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assertOutputAnswer(__dirname + 'output/01 - the question is the solution.txt');
27+
});
28+
29+
test("The start is the solution", function() {
30+
let inputFile = new File(__dirname + 'input/02 - the start is the solution.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assert.strictEqual(
35+
console.log.getCall(0).args[0],
36+
"L L L R"
37+
);
38+
});
39+
40+
test("From one side to the other", function() {
41+
let inputFile = new File(__dirname + 'input/03 - from one side to the other.txt');
42+
43+
execute(inputFile.readline.bind(inputFile));
44+
45+
assertOutputAnswer(__dirname + 'output/03 - from one side to the other.txt');
46+
});
47+
48+
test("Mix it up", function() {
49+
let inputFile = new File(__dirname + 'input/04 - mix it up.txt');
50+
51+
execute(inputFile.readline.bind(inputFile));
52+
53+
assertOutputAnswer(__dirname + 'output/04 - mix it up.txt');
54+
});
55+
56+
test("Rescue one", function() {
57+
let inputFile = new File(__dirname + 'input/05 - rescue one.txt');
58+
59+
execute(inputFile.readline.bind(inputFile));
60+
61+
assertOutputAnswer(__dirname + 'output/05 - rescue one.txt');
62+
});
63+
64+
test("Sorted", function() {
65+
let inputFile = new File(__dirname + 'input/06 - sorted.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assertOutputAnswer(__dirname + 'output/06 - sorted.txt');
70+
});
71+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R L R L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L R
2+
L L L R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R R R R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
R L R L
2+
L R L R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L R
2+
L L L L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
R R R R
2+
L L R L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R L R L

0 commit comments

Comments
 (0)