|
| 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 | +}); |
0 commit comments