Skip to content

Commit 29f51d0

Browse files
committed
Adding tests for "Roller coaster".
1 parent ab4f70b commit 29f51d0

9 files changed

+3125
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Tests for "Blunder - episode 3".
1111
- Tests for "CGX formatter".
1212
- Tests for "Genome sequencing".
13+
- Tests for "Roller coaster".
1314

1415
## [1.3.0] - 2022-03-02
1516
### Added
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Roller coaster" puzzle.
3+
*/
4+
function execute(readline) {
5+
var inputs = readline().split(' ');
6+
const L = parseInt(inputs[0]);
7+
const C = parseInt(inputs[1]);
8+
const N = parseInt(inputs[2]);
9+
for (let i = 0; i < N; i++) {
10+
const pi = parseInt(readline());
11+
}
12+
13+
// Write an answer using console.log()
14+
// To debug: console.error('Debug messages...');
15+
16+
console.log('answer');
17+
}
18+
19+
export { execute };
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/hard/rollerCoaster/rollerCoaster.js';
5+
6+
/**
7+
* Tests for the "Roller coaster" puzzle.
8+
*/
9+
suite('Roller coaster', 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 case', function() {
22+
let inputFile = new File('./test/training/hard/rollerCoaster/input/01 - simple case.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
7
29+
);
30+
});
31+
32+
test('1000 groups of a few people', function() {
33+
let inputFile = new File('./test/training/hard/rollerCoaster/input/02 - 1000 groups of a few people.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
3935
40+
);
41+
});
42+
43+
test('The same groups go on the ride several times during the day', function() {
44+
let inputFile = new File('./test/training/hard/rollerCoaster/input/03 - the same groups go on the ride several times during the day.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
15
51+
);
52+
});
53+
54+
test('All the people get on the roller coaster at least once', function() {
55+
let inputFile = new File('./test/training/hard/rollerCoaster/input/04 - all the people get on the roller coaster at least once.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
15000
62+
);
63+
});
64+
65+
test('High earnings during the day (> 2^32)', function() {
66+
let inputFile = new File('./test/training/hard/rollerCoaster/input/05 - high earnings during the day.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
4999975000
73+
);
74+
});
75+
76+
test('Works with a large dataset', function() {
77+
let inputFile = new File('./test/training/hard/rollerCoaster/input/06 - works with a large dataset.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
89744892565569
84+
);
85+
});
86+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3 3 4
2+
3
3+
1
4+
1
5+
2

0 commit comments

Comments
 (0)