|
| 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/training/medium/theGift/theGift.js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests for the "The gift" puzzle. |
| 9 | + */ |
| 10 | +suite('The gift', 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('Example 1', function() { |
| 23 | + let inputFile = new File('./test/training/medium/theGift/input/01 - example 1.txt'); |
| 24 | + |
| 25 | + execute(inputFile.readline.bind(inputFile)); |
| 26 | + |
| 27 | + assert.strictEqual( |
| 28 | + console.log.getCall(0).args[0], |
| 29 | + "IMPOSSIBLE" |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + test('Example 2', function() { |
| 34 | + let inputFile = new File('./test/training/medium/theGift/input/02 - example 2.txt'); |
| 35 | + |
| 36 | + execute(inputFile.readline.bind(inputFile)); |
| 37 | + |
| 38 | + assertOutputAnswer('./test/training/medium/theGift/output/02 - example 2.txt'); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Example 3', function() { |
| 42 | + let inputFile = new File('./test/training/medium/theGift/input/03 - example 3.txt'); |
| 43 | + |
| 44 | + execute(inputFile.readline.bind(inputFile)); |
| 45 | + |
| 46 | + assertOutputAnswer('./test/training/medium/theGift/output/03 - example 3.txt'); |
| 47 | + }); |
| 48 | + |
| 49 | + test('Impossible', function() { |
| 50 | + let inputFile = new File('./test/training/medium/theGift/input/04 - impossible.txt'); |
| 51 | + |
| 52 | + execute(inputFile.readline.bind(inputFile)); |
| 53 | + |
| 54 | + assert.strictEqual( |
| 55 | + console.log.getCall(0).args[0], |
| 56 | + "IMPOSSIBLE" |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Sort', function() { |
| 61 | + let inputFile = new File('./test/training/medium/theGift/input/05 - sort.txt'); |
| 62 | + |
| 63 | + execute(inputFile.readline.bind(inputFile)); |
| 64 | + |
| 65 | + assertOutputAnswer('./test/training/medium/theGift/output/05 - sort.txt'); |
| 66 | + }); |
| 67 | + |
| 68 | + test('Budget limit', function() { |
| 69 | + let inputFile = new File('./test/training/medium/theGift/input/06 - budget Limit.txt'); |
| 70 | + |
| 71 | + execute(inputFile.readline.bind(inputFile)); |
| 72 | + |
| 73 | + assertOutputAnswer('./test/training/medium/theGift/output/06 - budget Limit.txt'); |
| 74 | + }); |
| 75 | + |
| 76 | + test('Several solutions budget', function() { |
| 77 | + let inputFile = new File('./test/training/medium/theGift/input/07 - several solutions budget.txt'); |
| 78 | + |
| 79 | + execute(inputFile.readline.bind(inputFile)); |
| 80 | + |
| 81 | + assertOutputAnswer('./test/training/medium/theGift/output/07 - several solutions budget.txt'); |
| 82 | + }); |
| 83 | + |
| 84 | + test('Several solution fast', function() { |
| 85 | + let inputFile = new File('./test/training/medium/theGift/input/08 - several solution fast.txt'); |
| 86 | + |
| 87 | + execute(inputFile.readline.bind(inputFile)); |
| 88 | + |
| 89 | + assertOutputAnswer('./test/training/medium/theGift/output/08 - several solution fast.txt'); |
| 90 | + }); |
| 91 | + |
| 92 | + test('Big random', function() { |
| 93 | + let inputFile = new File('./test/training/medium/theGift/input/09 - big random.txt'); |
| 94 | + |
| 95 | + execute(inputFile.readline.bind(inputFile)); |
| 96 | + |
| 97 | + assertOutputAnswer('./test/training/medium/theGift/output/09 - big random.txt'); |
| 98 | + }); |
| 99 | +}); |
0 commit comments