Skip to content

Commit 74b3d13

Browse files
committed
Adding tests for "Vote counting".
1 parent 8cf1800 commit 74b3d13

File tree

8 files changed

+167
-0
lines changed

8 files changed

+167
-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
## [3.16.0] - 2022-12-31
3839
### Added
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\VoteCounting;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Vote counting" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/vote-counting
12+
*/
13+
class VoteCounting implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
fscanf($stdin, "%d", $M);
19+
for ($i = 0; $i < $N; $i++)
20+
{
21+
fscanf($stdin, "%s %d", $personName, $nbVote);
22+
}
23+
for ($i = 0; $i < $M; $i++)
24+
{
25+
fscanf($stdin, "%s %s", $voterName, $voteValue);
26+
}
27+
28+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
29+
30+
echo("output\n");
31+
}
32+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\VoteCounting;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\VoteCounting\VoteCounting;
9+
10+
/**
11+
* Tests for the "Vote counting" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\VoteCounting\VoteCounting
14+
* @group voteCounting
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new VoteCounting();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example".
26+
*
27+
* @group voteCounting_example
28+
*/
29+
public function testCanExecuteExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example.txt',
33+
"2 1" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Invalid voter".
39+
*
40+
* @group voteCounting_invalidVoter
41+
*/
42+
public function testCanExecuteInvalidVoter(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - invalid voter.txt',
46+
"1 2" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Too many votes".
52+
*
53+
* @group voteCounting_tooManyVotes
54+
*/
55+
public function testCanExecuteTooManyVotes(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - too many votes.txt',
59+
"1 3" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Maybe vote".
65+
*
66+
* @group voteCounting_maybeVote
67+
*/
68+
public function testCanExecuteMaybeVote(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - maybe vote.txt',
72+
"1 0" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Complex".
78+
*
79+
* @group voteCounting_complex
80+
*/
81+
public function testCanExecuteComplex(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - complex.txt',
85+
"2 1" . PHP_EOL
86+
);
87+
}
88+
}
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)