Skip to content

Commit b97f121

Browse files
committed
Adding tests for "Rotating arrows".
1 parent a8a7c1f commit b97f121

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Tests for "Dead men's shot".
3030
- Tests for "Darts".
3131
- Tests for "Add'em up".
32+
- Tests for "Rotating arrows".
3233

3334
### Fixed
3435
- File import for "A child's play".
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* The "Rotating arrows" puzzle.
3+
*/
4+
function execute(readline) {
5+
var inputs = readline().split(' ');
6+
const W = parseInt(inputs[0]);
7+
const H = parseInt(inputs[1]);
8+
var inputs = readline().split(' ');
9+
const x = parseInt(inputs[0]);
10+
const y = parseInt(inputs[1]);
11+
for (let i = 0; i < H; i++) {
12+
const line = readline(); // The line of w arrows represented by ascii char ^v<>
13+
}
14+
15+
// Write an answer using console.log()
16+
// To debug: console.error('Debug messages...');
17+
18+
console.log('0');
19+
}
20+
21+
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/rotatingArrows/rotatingArrows.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Rotating arrows", 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("Simple", function() {
22+
let inputFile = new File(__dirname + 'input/01 - simple.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
2
29+
);
30+
});
31+
32+
test("More rotate", function() {
33+
let inputFile = new File(__dirname + 'input/02 - more rotate.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
8
40+
);
41+
});
42+
43+
test("Overflow", function() {
44+
let inputFile = new File(__dirname + 'input/03 - overflow.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
3
51+
);
52+
});
53+
54+
test("Repeat", function() {
55+
let inputFile = new File(__dirname + 'input/04 - repeat.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
18
62+
);
63+
});
64+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2 1
2+
0 0
3+
^v
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3 3
2+
2 1
3+
>v>
4+
><v
5+
^^<
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5 5
2+
2 2
3+
<><><
4+
<><><
5+
<><><
6+
<><><
7+
<><><
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6 5
2+
2 2
3+
<><><>
4+
<>^>>>
5+
^^<^<>
6+
<><><>
7+
<vvvvv

0 commit comments

Comments
 (0)