Skip to content

Commit 7972eee

Browse files
committed
Adding tests for "Dolbear's law".
1 parent e95d96e commit 7972eee

12 files changed

+205
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "Walk on a die".
10+
- Tests for "Dolbear's law".
1011

1112
## [1.5.0] - 2022-03-03
1213
### Added
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The "Dolbear's Law" puzzle.
3+
*/
4+
function execute(readline) {
5+
const M = parseInt(readline());
6+
for (let i = 0; i < M; i++) {
7+
const LINE = readline();
8+
}
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
console.log('answer');
14+
}
15+
16+
export { execute };
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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/dolbearsLaw/dolbearsLaw.js';
6+
7+
/**
8+
* Tests for the "Dolbear's Law" puzzle.
9+
*/
10+
suite("Dolbear's Law", function() {
11+
const sandbox = sinon.createSandbox();
12+
13+
setup(function () {
14+
sandbox.stub(console, "log");
15+
});
16+
17+
teardown(function () {
18+
sandbox.restore();
19+
});
20+
21+
22+
test('The random is in the spring', function() {
23+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/01 - the random is in the spring.txt');
24+
25+
execute(inputFile.readline.bind(inputFile));
26+
27+
assertOutputAnswer('./test/community/training/easy/dolbearsLaw/output/01 - the random is in the spring.txt');
28+
});
29+
30+
test('Winter is coming', function() {
31+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/02 - winter is coming.txt');
32+
33+
execute(inputFile.readline.bind(inputFile));
34+
35+
assert.strictEqual(
36+
console.log.getCall(0).args[0],
37+
4.9
38+
);
39+
});
40+
41+
test('Jiminy beats the measure', function() {
42+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/03 - jiminy beats the measure.txt');
43+
44+
execute(inputFile.readline.bind(inputFile));
45+
46+
assertOutputAnswer('./test/community/training/easy/dolbearsLaw/output/03 - jiminy beats the measure.txt');
47+
});
48+
49+
test('Jiminy nearly died of cold...', function() {
50+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/04 - jiminy nearly died of cold.txt');
51+
52+
execute(inputFile.readline.bind(inputFile));
53+
54+
assert.strictEqual(
55+
console.log.getCall(0).args[0],
56+
4.4
57+
);
58+
});
59+
60+
test('An hour in summer', function() {
61+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/05 - an hour in summer.txt');
62+
63+
execute(inputFile.readline.bind(inputFile));
64+
65+
assertOutputAnswer('./test/community/training/easy/dolbearsLaw/output/05 - an hour in summer.txt');
66+
});
67+
68+
test('30MinutesOfHeatWave', function() {
69+
let inputFile = new File('./test/community/training/easy/dolbearsLaw/input/06 - 30 minutes of heat wave.txt');
70+
71+
execute(inputFile.readline.bind(inputFile));
72+
73+
assert.strictEqual(
74+
console.log.getCall(0).args[0],
75+
"42.0"
76+
);
77+
});
78+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
8 8 6 3 2 4 8 6 9 5 2 1 5 2 8
3+
8 3 3 6 7 2 8 1 7 4 5 4 2 3 9
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
0 1 1 0 0 1 0 1 1 0 0 1 0 0 1
3+
0 0 1 0 0 0 1 0 0 0 0 0 0 0 0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3+
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4+
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
60
2+
13 14 12 10 12 11 11 10 10 13 14 14 14 10 14
3+
11 12 11 14 13 10 10 12 12 13 11 13 11 12 13
4+
12 14 10 11 11 10 11 10 10 11 10 14 11 14 13
5+
14 10 13 10 11 13 10 11 11 12 13 10 10 10 10
6+
11 10 14 11 10 13 12 14 14 13 13 11 13 14 13
7+
14 10 10 13 12 12 11 10 10 11 14 14 11 11 14
8+
12 10 12 13 14 12 11 13 13 14 13 12 12 10 12
9+
12 10 10 10 13 12 10 11 12 11 11 14 10 13 11
10+
12 12 10 11 11 14 12 13 11 11 13 12 11 14 11
11+
14 13 13 13 13 10 14 13 13 13 14 10 13 10 10
12+
10 12 11 13 14 11 11 12 10 12 12 14 12 10 14
13+
14 10 11 13 10 14 11 13 14 10 13 11 12 10 13
14+
11 14 14 14 12 11 12 13 13 13 12 13 14 12 14
15+
11 13 14 12 12 11 13 12 14 12 10 13 13 10 13
16+
14 14 14 12 14 10 12 10 13 11 10 14 12 11 13
17+
13 12 14 11 13 13 14 14 14 13 11 12 11 13 11
18+
12 12 11 11 12 10 13 10 11 12 14 12 10 12 12
19+
11 13 14 11 13 11 12 11 13 11 13 10 14 14 12
20+
13 10 14 10 13 11 10 13 11 13 12 11 12 10 14
21+
10 13 10 12 10 10 12 13 10 11 11 14 14 13 11
22+
12 10 11 13 13 12 14 11 13 10 11 12 10 11 13
23+
12 14 14 12 10 13 13 10 14 14 14 10 12 14 14
24+
11 13 12 10 10 14 11 13 11 14 13 12 11 12 10
25+
14 11 12 10 11 11 10 11 11 11 10 10 11 10 13
26+
14 13 12 12 14 12 13 12 12 12 10 14 14 11 13
27+
10 10 12 12 11 12 11 10 12 13 11 13 12 12 10
28+
12 12 13 11 11 11 12 10 11 11 12 11 14 11 10
29+
10 13 14 12 10 13 10 14 14 13 14 13 10 14 12
30+
12 10 10 10 12 14 12 11 10 13 11 14 12 12 11
31+
10 10 14 12 11 14 12 12 12 10 11 10 11 13 11
32+
13 11 11 12 10 12 13 12 10 14 11 12 11 11 14
33+
13 10 10 12 14 14 13 13 12 12 13 13 11 13 11
34+
11 13 12 13 14 12 10 13 10 13 14 13 13 12 10
35+
10 13 14 11 10 14 13 10 10 14 10 14 13 12 14
36+
11 11 10 13 12 12 11 13 10 13 10 13 11 12 11
37+
14 13 11 10 11 13 10 10 10 10 10 11 10 13 13
38+
13 11 11 13 10 13 10 13 10 14 14 12 13 12 10
39+
14 12 10 11 13 10 10 13 11 13 12 12 13 13 13
40+
12 10 14 12 13 14 14 11 12 12 14 11 11 12 10
41+
14 12 11 12 10 13 12 14 11 12 14 14 11 14 10
42+
14 11 10 12 13 11 11 10 13 10 10 10 13 11 12
43+
13 14 11 13 13 14 13 11 14 10 10 14 12 11 13
44+
13 10 11 12 14 13 13 10 12 14 13 11 11 14 12
45+
12 11 14 13 14 13 10 12 10 10 12 12 10 13 13
46+
11 11 14 14 14 14 14 11 10 14 14 10 13 12 13
47+
11 13 11 11 11 11 13 11 11 12 10 10 13 10 11
48+
12 14 10 10 13 10 13 10 14 13 10 12 11 11 10
49+
11 11 13 11 14 10 11 11 10 13 12 13 11 13 10
50+
11 10 13 13 14 12 11 11 12 14 14 12 11 12 13
51+
10 10 13 11 12 11 13 11 12 12 13 10 14 13 11
52+
12 13 14 14 13 13 13 12 10 12 14 14 11 11 11
53+
14 10 10 13 11 11 11 12 10 12 14 10 13 13 10
54+
10 12 11 12 14 13 12 10 11 12 13 13 11 10 11
55+
12 14 13 10 10 12 13 10 13 11 10 13 13 11 10
56+
11 11 13 13 12 14 13 11 10 14 13 11 11 10 10
57+
13 13 14 12 11 13 10 12 14 14 13 11 10 12 10
58+
13 10 11 13 10 14 12 10 14 13 11 13 10 10 10
59+
13 10 11 11 12 14 13 14 12 11 13 13 11 12 11
60+
14 12 12 10 11 13 12 10 11 11 13 10 12 10 13
61+
13 10 10 10 10 11 12 10 13 13 11 10 12 11 11
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
30
2+
15 17 19 20 16 16 17 19 15 20 18 20 15 18 18
3+
19 19 18 17 18 16 15 16 15 18 17 18 20 18 19
4+
17 17 19 16 19 20 19 19 16 15 19 15 17 19 20
5+
16 20 17 15 15 15 18 18 18 16 16 15 18 18 17
6+
19 15 18 18 20 15 19 19 19 19 18 17 15 17 18
7+
19 20 17 18 19 17 17 19 18 19 20 15 17 19 17
8+
15 17 20 20 15 19 18 15 15 17 19 16 19 20 15
9+
17 17 16 15 19 16 19 16 19 17 15 15 17 20 17
10+
19 20 16 17 19 17 16 18 19 19 15 15 18 15 20
11+
17 19 17 15 20 20 15 16 15 18 19 16 15 20 16
12+
15 16 15 18 20 18 16 18 20 20 20 15 17 19 15
13+
18 15 20 17 19 17 15 19 15 17 18 17 16 17 18
14+
18 17 20 16 20 15 20 20 17 15 17 15 18 19 20
15+
19 16 16 17 16 20 20 15 15 19 19 19 18 18 20
16+
16 20 18 16 15 16 19 19 18 20 19 15 20 16 19
17+
19 18 17 20 17 18 19 16 18 16 19 16 16 17 19
18+
19 15 16 19 17 17 20 15 15 15 16 17 16 15 16
19+
19 16 18 18 17 19 19 18 18 18 17 19 17 15 18
20+
15 18 17 15 15 19 17 17 16 20 18 20 20 18 20
21+
16 16 17 18 17 18 17 19 17 20 20 20 18 19 17
22+
16 19 16 20 15 15 17 19 20 17 19 16 19 20 17
23+
16 16 18 16 16 19 19 17 16 20 19 19 17 16 19
24+
18 20 17 18 20 15 15 20 20 20 19 20 19 18 18
25+
16 16 19 18 19 20 19 15 16 18 20 17 20 19 19
26+
15 16 16 20 18 18 15 20 20 18 19 19 17 16 17
27+
19 15 18 16 16 16 20 19 15 17 18 16 16 20 19
28+
15 19 18 16 19 16 20 15 15 18 19 19 19 20 15
29+
17 20 17 18 19 19 19 19 20 20 19 15 17 19 19
30+
15 17 20 15 15 19 19 20 19 17 17 19 17 16 18
31+
18 19 15 18 19 18 16 17 20 18 19 16 15 17 19
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
14.9
2+
14.9

0 commit comments

Comments
 (0)