Skip to content

Commit f2aa53b

Browse files
committed
Adding tests for "The gift".
1 parent 55a5047 commit f2aa53b

19 files changed

+3303
-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 "Scrabble".
1111
- Tests for "Stock exchange losses".
1212
- Tests for "Telephone numbers".
13+
- Tests for "The gift".
1314

1415
## [1.2.0] - 2022-03-02
1516
### Added
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The "The gift" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
const C = parseInt(readline());
7+
for (let i = 0; i < N; i++) {
8+
const B = parseInt(readline());
9+
}
10+
11+
// Write an answer using console.log()
12+
// To debug: console.error('Debug messages...');
13+
14+
console.log('IMPOSSIBLE');
15+
}
16+
17+
export { execute };
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
20
4+
20
5+
40
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
40
4+
40
5+
40
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
100
4+
1
5+
60
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
20
4+
20
5+
20
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
3
3+
3
4+
3
5+
3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
100
3+
10
4+
100
5+
100
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
10
3+
5
4+
10
5+
5

0 commit comments

Comments
 (0)