Skip to content

Commit 9923123

Browse files
committed
Adding tests for "Vote counting".
1 parent 19d10c6 commit 9923123

File tree

8 files changed

+146
-0
lines changed

8 files changed

+146
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Tests for "2×2×2 rubik’s cube movements".
3434
- Tests for "The polish dictionary".
3535
- Tests for "1010(1)".
36+
- Tests for "Vote counting".
3637

3738
## [1.16.0] - 2022-12-31
3839
### Added
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* The "Vote counting" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/vote-counting}
4+
*/
5+
function execute(readline) {
6+
const N = parseInt(readline());
7+
const M = parseInt(readline());
8+
for (let i = 0; i < N; i++) {
9+
var inputs = readline().split(' ');
10+
const personName = inputs[0];
11+
const nbVote = parseInt(inputs[1]);
12+
}
13+
for (let i = 0; i < M; i++) {
14+
var inputs = readline().split(' ');
15+
const voterName = inputs[0];
16+
const voteValue = inputs[1];
17+
}
18+
19+
// Write an answer using console.log()
20+
// To debug: console.error('Debug messages...');
21+
22+
console.log('output');
23+
}
24+
25+
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/medium/voteCounting/voteCounting.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Vote counting", 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("Example", function() {
21+
let inputFile = new File(__dirname + 'input/01 - example.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"2 1"
28+
);
29+
});
30+
31+
test("Invalid voter", function() {
32+
let inputFile = new File(__dirname + 'input/02 - invalid voter.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"1 2"
39+
);
40+
});
41+
42+
test("Too many votes", function() {
43+
let inputFile = new File(__dirname + 'input/03 - too many votes.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"1 3"
50+
);
51+
});
52+
53+
test("Maybe vote", function() {
54+
let inputFile = new File(__dirname + 'input/04 - maybe vote.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"1 0"
61+
);
62+
});
63+
64+
test("Complex", function() {
65+
let inputFile = new File(__dirname + 'input/05 - complex.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"2 1"
72+
);
73+
});
74+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2
2+
3
3+
Albert 2
4+
Roger 1
5+
Albert Yes
6+
Roger No
7+
Albert Yes
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1
2+
4
3+
Albert 3
4+
CodinGame Yes
5+
Albert Yes
6+
Albert No
7+
Albert No
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
3
2+
6
3+
Yohann 1
4+
Sandra 3
5+
Capucine 1
6+
Capucine Yes
7+
Sandra No
8+
Yohann Yes
9+
Sandra No
10+
Yohann Yes
11+
Sandra No
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2
2+
2
3+
Kevin 1
4+
Charlotte 1
5+
Kevin Maybe
6+
Charlotte Yes
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
4
2+
9
3+
Albert 2
4+
Roger 1
5+
Thierry 1
6+
Valérie 3
7+
Albert Yes
8+
Valérie Yes
9+
Erwan No
10+
Albert No
11+
Thierry Yes
12+
Valérie Yes
13+
Valérie No
14+
Valérie Non
15+
Roger Maybe

0 commit comments

Comments
 (0)