Skip to content

Commit 2daed22

Browse files
committed
Adding tests for "A coin guessing game".
1 parent 5537e74 commit 2daed22

File tree

15 files changed

+212
-0
lines changed

15 files changed

+212
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- Tests for "Futoshiki solver".
3535
- Tests for "Frog exchange".
3636
- Tests for "Fair numbering".
37+
- Tests for "A coin guessing game".
3738

3839
## [1.11.0] - 2022-07-31
3940
### Added
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* The "A coin guessing game" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/a-coin-guessing-game}
4+
*/
5+
function execute(readline) {
6+
var inputs = readline().split(' ');
7+
const N = parseInt(inputs[0]);
8+
const T = parseInt(inputs[1]);
9+
for (let i = 0; i < T; i++) {
10+
var inputs = readline().split(' ');
11+
for (let j = 0; j < N; j++) {
12+
const C = parseInt(inputs[j]);
13+
}
14+
}
15+
16+
// Write an answer using console.log()
17+
// To debug: console.error('Debug messages...');
18+
19+
console.log('2 4 6...');
20+
}
21+
22+
export { execute };
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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/community/training/medium/aCoinGuessingGame/aCoinGuessingGame.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("A coin guessing game", 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("2 coins", function() {
22+
let inputFile = new File(__dirname + 'input/01 - 2 coins.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
"4 2"
29+
);
30+
});
31+
32+
test("3 coins", function() {
33+
let inputFile = new File(__dirname + 'input/02 - 3 coins.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
"2 4 6"
40+
);
41+
});
42+
43+
test("4 coins", function() {
44+
let inputFile = new File(__dirname + 'input/03 - 4 coins.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
"2 8 4 6"
51+
);
52+
});
53+
54+
test("5 coins", function() {
55+
let inputFile = new File(__dirname + 'input/04 - 5 coins.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
"10 4 8 2 6"
62+
);
63+
});
64+
65+
test("10 coins", function() {
66+
let inputFile = new File(__dirname + 'input/05 - 10 coins.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
"18 16 14 12 2 10 20 8 4 6"
73+
);
74+
});
75+
76+
test("25 coins", function() {
77+
let inputFile = new File(__dirname + 'input/06 - 25 coins.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
"16 30 26 46 12 34 36 10 22 38 24 44 8 6 20 28 50 40 4 48 42 2 18 14 32"
84+
);
85+
});
86+
87+
test("50 coins", function() {
88+
let inputFile = new File(__dirname + 'input/07 - 50 coins.txt');
89+
90+
execute(inputFile.readline.bind(inputFile));
91+
92+
assertOutputAnswer(__dirname + 'output/07 - 50 coins.txt');
93+
});
94+
95+
test("100 coins", function() {
96+
let inputFile = new File(__dirname + 'input/08 - 100 coins.txt');
97+
98+
execute(inputFile.readline.bind(inputFile));
99+
100+
assertOutputAnswer(__dirname + 'output/08 - 100 coins.txt');
101+
});
102+
103+
test("150 coins", function() {
104+
let inputFile = new File(__dirname + 'input/09 - 150 coins.txt');
105+
106+
execute(inputFile.readline.bind(inputFile));
107+
108+
assertOutputAnswer(__dirname + 'output/09 - 150 coins.txt');
109+
});
110+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2 3
2+
4 2
3+
2 4
4+
4 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3 2
2+
3 1 6
3+
4 1 6
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
4 3
2+
4 1 8 6
3+
5 6 8 1
4+
6 3 1 4
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
5 4
2+
2 10 6 3 5
3+
5 1 9 3 2
4+
9 8 10 4 7
5+
4 1 9 5 2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
10 9
2+
14 1 15 13 2 7 16 19 11 4
3+
11 13 12 16 18 2 4 8 6 14
4+
1 2 19 10 20 12 14 4 16 15
5+
18 3 14 17 11 2 7 15 19 20
6+
18 10 6 2 14 15 4 13 12 16
7+
10 9 18 15 4 12 5 3 19 13
8+
1 11 20 7 2 14 19 4 16 15
9+
11 19 17 15 7 2 13 3 14 1
10+
14 10 13 17 6 9 1 7 3 8
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
25 7
2+
45 16 28 49 14 41 38 34 43 23 27 25 30 9 50 29 37 36 24 5 22 46 39 15 35
3+
5 48 21 38 43 47 41 15 22 28 7 4 23 8 33 6 12 35 30 20 32 1 13 34 45
4+
16 31 46 23 48 37 15 41 19 21 12 34 18 5 6 8 33 29 17 2 14 13 35 30 49
5+
27 37 38 28 8 9 17 29 16 43 41 47 3 10 50 7 45 40 34 21 49 44 5 39 36
6+
7 3 44 9 50 29 13 22 37 19 24 26 41 47 28 18 6 39 49 34 25 43 10 35 16
7+
7 45 14 40 5 49 17 25 4 28 23 39 34 6 19 13 29 12 43 24 41 15 33 1 3
8+
3 22 27 49 33 34 15 25 42 28 26 16 37 47 43 48 24 12 18 44 19 20 13 7 35
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
50 12
2+
79 8 86 54 99 68 72 4 88 87 100 37 33 76 65 95 74 51 62 94 10 28 92 46 7 84 24 66 25 16 27 53 85 64 13 49 59 48 17 12 32 90 77 35 82 43 26 42 3 75
3+
47 12 50 66 77 16 32 24 82 69 45 78 7 53 51 52 8 13 46 14 79 100 11 74 58 2 91 1 62 96 22 73 34 42 88 10 38 6 89 31 23 4 63 81 28 56 37 80 99 87
4+
90 75 87 24 58 15 86 79 51 8 32 57 69 88 83 21 76 25 11 13 100 31 49 38 55 22 26 35 59 77 30 64 37 99 72 16 29 14 89 34 47 44 63 95 50 62 85 41 10 42
5+
30 58 84 31 99 50 1 82 54 71 55 98 70 3 37 26 49 5 83 100 2 87 29 66 13 56 79 81 61 7 96 45 97 28 62 6 17 90 32 33 52 75 94 69 73 67 74 27 93 92
6+
38 63 50 72 55 99 48 40 76 11 86 42 43 98 64 74 26 93 44 6 70 69 56 54 52 46 13 10 36 53 82 49 67 2 91 32 16 62 24 75 3 79 39 4 22 21 57 96 17 89
7+
40 60 58 22 62 78 71 1 49 65 20 72 84 21 68 85 81 44 9 12 41 29 59 93 67 16 48 15 10 2 90 13 57 30 52 33 45 70 14 37 95 42 92 83 23 94 54 34 98 39
8+
78 29 67 24 89 74 88 21 66 41 39 56 77 64 90 80 33 2 65 36 60 26 34 48 51 76 58 9 11 25 44 1 6 72 87 83 84 10 69 62 99 54 96 42 17 53 18 22 16 55
9+
77 80 9 69 15 42 6 4 27 58 51 2 79 1 20 56 3 17 54 57 93 44 18 100 48 71 33 30 8 29 40 91 64 63 89 96 72 11 97 25 23 78 21 61 41 19 36 65 12 81
10+
98 43 11 41 87 29 57 37 34 75 17 79 86 61 76 62 89 4 67 65 18 27 74 95 9 20 52 63 68 39 73 7 35 80 30 56 5 54 91 23 33 88 97 70 71 21 31 12 45 6
11+
22 3 64 26 32 56 5 83 68 63 20 24 52 50 82 40 86 7 47 100 81 17 16 58 95 31 70 18 62 60 80 12 2 51 67 15 72 61 90 89 11 30 46 36 38 93 28 57 6 78
12+
27 11 14 41 88 72 76 7 35 89 20 83 8 95 78 31 9 61 25 34 69 33 6 50 54 29 36 1 85 60 5 13 97 100 30 51 45 91 21 62 66 12 58 80 63 71 74 40 26 77
13+
63 72 48 68 12 77 8 60 9 39 54 38 35 45 16 44 28 40 43 50 18 11 56 83 57 99 71 53 37 93 74 82 25 61 92 75 95 6 49 90 19 22 98 81 1 34 14 26 46 5

0 commit comments

Comments
 (0)