Skip to content

Commit c2f356b

Browse files
committed
Adding tests for "Walk on a die".
1 parent 826f6f1 commit c2f356b

File tree

11 files changed

+162
-0
lines changed

11 files changed

+162
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Tests for "Walk on a die".
10+
711
## [1.5.0] - 2022-03-03
812
### Added
913
- Tests for "Blowing fuse".
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "Walk on a die" puzzle.
3+
*/
4+
function execute(readline) {
5+
for (let i = 0; i < 3; i++) {
6+
const line = readline(); // One line out of three in the string describing the starting position.
7+
}
8+
const commands = readline(); // The sequence of ULDR-characters describing the steps to perform.
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
14+
// The number on the side you end up on after having performed `commands`.
15+
console.log('number');
16+
}
17+
18+
export { execute };
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/walkOnADie/walkOnADie.js';
5+
6+
/**
7+
* Tests for the "Walk on a die" puzzle.
8+
*/
9+
suite('Walk on a die', 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('Test 1', function() {
22+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/01 - test 1.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
1
29+
);
30+
});
31+
32+
test('Test 2', function() {
33+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/02 - test 2.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
2
40+
);
41+
});
42+
43+
test('Test 3', function() {
44+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/03 - test 3.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
6
51+
);
52+
});
53+
54+
test('Test 4', function() {
55+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/04 - test 4.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
2
62+
);
63+
});
64+
65+
test('Test 5', function() {
66+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/05 - test 5.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
5
73+
);
74+
});
75+
76+
test('Test 6', function() {
77+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/06 - test 6.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
5
84+
);
85+
});
86+
87+
test('Test 7', function() {
88+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/07 - test 7.txt');
89+
90+
execute(inputFile.readline.bind(inputFile));
91+
92+
assert.strictEqual(
93+
console.log.getCall(0).args[0],
94+
3
95+
);
96+
});
97+
98+
test('Test 8', function() {
99+
let inputFile = new File('./test/community/training/easy/walkOnADie/input/08 - test 8.txt');
100+
101+
execute(inputFile.readline.bind(inputFile));
102+
103+
assert.strictEqual(
104+
console.log.getCall(0).args[0],
105+
5
106+
);
107+
});
108+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
2354
3+
6
4+
DLU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
3146
3+
5
4+
U
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
5
2+
6413
3+
2
4+
L
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
6
2+
4532
3+
1
4+
UU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
1463
3+
5
4+
LL
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
5423
3+
6
4+
ULRD
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
6
2+
5324
3+
1
4+
ULDR

0 commit comments

Comments
 (0)