Skip to content

Commit a7d0db4

Browse files
committed
Adding tests for "A coin guessing game".
1 parent e411fdc commit a7d0db4

File tree

15 files changed

+251
-0
lines changed

15 files changed

+251
-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
## [3.11.0] - 2022-07-31
3940
### Added
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\ACoinGuessingGame;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "A coin guessing game" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/a-coin-guessing-game
12+
*/
13+
class ACoinGuessingGame implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d", $N, $T);
18+
for ($i = 0; $i < $T; $i++)
19+
{
20+
$inputs = explode(" ", fgets($stdin));
21+
for ($j = 0; $j < $N; $j++)
22+
{
23+
$C = intval($inputs[$j]);
24+
}
25+
}
26+
27+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
28+
29+
echo("2 4 6...\n");
30+
}
31+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\ACoinGuessingGame;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\ACoinGuessingGame\ACoinGuessingGame;
9+
10+
/**
11+
* Tests for the "A coin guessing game" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\ACoinGuessingGame\ACoinGuessingGame
14+
* @group aCoinGuessingGame
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new ACoinGuessingGame();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "2 coins".
26+
*
27+
* @group aCoinGuessingGame_2Coins
28+
*/
29+
public function testCanExecute2Coins(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - 2 coins.txt',
33+
"4 2" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "3 coins".
39+
*
40+
* @group aCoinGuessingGame_3Coins
41+
*/
42+
public function testCanExecute3Coins(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - 3 coins.txt',
46+
"2 4 6" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "4 coins".
52+
*
53+
* @group aCoinGuessingGame_4Coins
54+
*/
55+
public function testCanExecute4Coins(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - 4 coins.txt',
59+
"2 8 4 6" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "5 coins".
65+
*
66+
* @group aCoinGuessingGame_5Coins
67+
*/
68+
public function testCanExecute5Coins(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - 5 coins.txt',
72+
"10 4 8 2 6" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "10 coins".
78+
*
79+
* @group aCoinGuessingGame_10Coins
80+
*/
81+
public function testCanExecute10Coins(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 10 coins.txt',
85+
"18 16 14 12 2 10 20 8 4 6" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "25 coins".
91+
*
92+
* @group aCoinGuessingGame_25Coins
93+
*/
94+
public function testCanExecute25Coins(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - 25 coins.txt',
98+
"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" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "50 coins".
104+
*
105+
* @group aCoinGuessingGame_50Coins
106+
*/
107+
public function testCanExecute50Coins(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - 50 coins.txt',
111+
file_get_contents(__DIR__ . '/output/07 - 50 coins.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "100 coins".
117+
*
118+
* @group aCoinGuessingGame_100Coins
119+
*/
120+
public function testCanExecute100Coins(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - 100 coins.txt',
124+
file_get_contents(__DIR__ . '/output/08 - 100 coins.txt')
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "150 coins".
130+
*
131+
* @group aCoinGuessingGame_150Coins
132+
*/
133+
public function testCanExecute150Coins(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - 150 coins.txt',
137+
file_get_contents(__DIR__ . '/output/09 - 150 coins.txt')
138+
);
139+
}
140+
}
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)