Skip to content

Commit 168d846

Browse files
committed
Adding tests for "Distributing candy".
1 parent c6b3a7b commit 168d846

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Tests for "A mountain of a mole hill".
3636
- Tests for "Where's Wally".
3737
- Tests for "Feature extraction".
38+
- Tests for "Distributing candy".
3839

3940
### Fixed
4041
- File import for "A child's play".
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Distributing candy" puzzle.
3+
*/
4+
function execute(readline) {
5+
var inputs = readline().split(' ');
6+
const n = parseInt(inputs[0]);
7+
const m = parseInt(inputs[1]);
8+
var inputs = readline().split(' ');
9+
for (let i = 0; i < n; i++) {
10+
const x = parseInt(inputs[i]);
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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/easy/distributingCandy/distributingCandy.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Distributing candy", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("Test 1", function() {
21+
let inputFile = new File(__dirname + 'input/01 - test 1.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
2
28+
);
29+
});
30+
31+
test("Test 2", function() {
32+
let inputFile = new File(__dirname + 'input/02 - test 2.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
5
39+
);
40+
});
41+
42+
test("Test 3", function() {
43+
let inputFile = new File(__dirname + 'input/03 - test 3.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
23
50+
);
51+
});
52+
53+
test("Test 4", function() {
54+
let inputFile = new File(__dirname + 'input/04 - test 4.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
13
61+
);
62+
});
63+
64+
test("Test 5", function() {
65+
let inputFile = new File(__dirname + 'input/05 - test 5.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
20
72+
);
73+
});
74+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
6 3
2+
7 1 3 10 12 10
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
26 5
2+
0 0 16 61 22 26 58 38 61 68 2 59 3 23 67 68 33 90 27 35 49 97 8 97 10 25
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
72 21
2+
0 1 19 31 36 23 6 35 11 73 38 4 22 70 16 49 31 87 62 91 61 72 47 53 4 21 67 65 77 34 60 27 96 59 9 70 13 29 79 32 81 47 30 82 87 93 10 89 97 21 17 68 55 14 82 69 46 85 7 28 66 87 49 97 81 0 58 90 3 35 96 20
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
240 41
2+
0 5 42 25 30 62 20 78 29 35 73 87 38 3 23 94 92 9 94 35 45 1 11 66 47 19 2 41 93 60 16 99 39 79 59 65 65 42 58 71 73 56 36 70 99 32 8 51 79 6 28 58 9 8 42 5 26 31 43 8 31 45 91 37 45 36 23 92 2 76 14 56 67 35 75 77 89 56 13 49 83 73 40 64 97 38 54 76 0 82 51 0 30 20 54 95 4 94 37 16 10 29 13 9 22 55 67 35 95 67 59 91 91 28 61 97 8 12 85 40 58 91 88 21 85 96 77 12 25 60 49 18 2 87 16 65 81 29 41 71 35 96 23 86 49 2 35 80 31 96 73 29 78 57 0 61 58 72 62 6 49 38 34 25 70 35 25 84 44 55 42 1 28 2 15 77 34 77 40 79 26 26 38 33 78 5 67 27 97 60 97 67 70 31 10 46 53 10 65 6 81 72 21 63 98 90 19 73 98 38 94 11 4 76 83 33 0 55 17 73 18 9 69 20 46 62 93 62 40 69 55 26 82 97 76 33 45 55 83 16
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
192 51
2+
0 1 53 98 15 96 37 5 48 90 14 1 48 98 32 9 59 21 35 53 34 16 92 41 64 8 15 12 57 19 32 63 76 33 44 90 67 70 11 51 72 73 98 50 80 20 7 69 67 81 88 9 19 70 50 72 37 50 36 66 27 32 50 96 74 78 32 20 91 28 72 62 23 43 13 19 84 16 57 78 37 30 91 59 34 48 1 4 64 31 29 87 66 74 72 81 32 99 64 80 34 15 4 71 70 77 19 68 55 32 89 56 48 44 77 58 18 83 79 76 49 46 62 61 98 16 23 62 83 27 25 68 9 21 77 46 33 96 80 45 25 64 89 34 85 70 83 30 5 1 0 66 60 53 26 58 82 13 82 89 1 14 21 54 76 53 26 24 48 88 85 35 64 84 84 98 64 63 8 95 2 49 75 74 56 83 62 63 33 51 48 16

0 commit comments

Comments
 (0)