Skip to content

Commit 938040a

Browse files
committed
Adding tests for "Sweet spot".
1 parent dbd9be5 commit 938040a

19 files changed

+422
-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 "Are the clumps normal".
3434
- Tests for "Bulk email generator".
3535
- Tests for "Snail run".
36+
- Tests for "Sweet spot".
3637

3738
## [3.8.0] - 2022-04-30
3839
### Added
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\SweetSpot;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Sweet spot" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/sweet-spot
12+
*/
13+
class SweetSpot implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
for ($i = 0; $i < $N; $i++)
19+
{
20+
$line = stream_get_line($stdin, 30 + 1, "\n");
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
25+
26+
echo("answer\n");
27+
}
28+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\SweetSpot;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\SweetSpot\SweetSpot;
9+
10+
/**
11+
* Tests for the "Sweet spot" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\SweetSpot\SweetSpot
14+
* @group sweetSpot
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SweetSpot();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "First attempt with A-bomb".
26+
*
27+
* @group sweetSpot_firstAttemptWithABomb
28+
*/
29+
public function testCanExecuteFirstAttemptWithABomb(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - first attempt with a-bomb.txt',
33+
file_get_contents(__DIR__ . '/output/01 - first attempt with a-bomb.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "First attempt with H-bomb".
39+
*
40+
* @group sweetSpot_firstAttemptWithHBomb
41+
*/
42+
public function testCanExecuteFirstAttemptWithHBomb(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - first attempt with h-bomb.txt',
46+
file_get_contents(__DIR__ . '/output/02 - first attempt with h-bomb.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Real case : A/H-bomb".
52+
*
53+
* @group sweetSpot_realCaseAHBomb
54+
*/
55+
public function testCanExecuteRealCaseAHBomb(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - real case : A H-bomb.txt',
59+
file_get_contents(__DIR__ . '/output/03 - real case : A H-bomb.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "First attempt with B-bomb".
65+
*
66+
* @group sweetSpot_firstAttemptWithBBomb
67+
*/
68+
public function testCanExecuteFirstAttemptWithBBomb(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - first attempt with b-bomb.txt',
72+
file_get_contents(__DIR__ . '/output/04 - first attempt with b-bomb.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Small map".
78+
*
79+
* @group sweetSpot_smallMap
80+
*/
81+
public function testCanExecuteSmallMap(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - small map.txt',
85+
file_get_contents(__DIR__ . '/output/05 - small map.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Real case : all bombs".
91+
*
92+
* @group sweetSpot_realCaseAllBombs
93+
*/
94+
public function testCanExecuteRealCaseAllBombs(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - real case : all bombs.txt',
98+
file_get_contents(__DIR__ . '/output/06 - real case : all bombs.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Damaged map".
104+
*
105+
* @group sweetSpot_damagedMap
106+
*/
107+
public function testCanExecuteDamagedMap(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - damaged map.txt',
111+
file_get_contents(__DIR__ . '/output/07 - damaged map.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "No explosions".
117+
*
118+
* @group sweetSpot_noExplosions
119+
*/
120+
public function testCanExecuteNoExplosions(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - no explosions.txt',
124+
file_get_contents(__DIR__ . '/output/08 - no explosions.txt')
125+
);
126+
}
127+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
15
2+
000000000000000
3+
A00A0000000000A
4+
000000000000000
5+
000000000000000
6+
000000000000000
7+
000000000000000
8+
000000000000000
9+
000000000000000
10+
0000000A0000000
11+
000000000000000
12+
000000000000000
13+
000000000000000
14+
000000000000000
15+
000000000000000
16+
A000000000000AA
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
18
2+
H00000000000000000
3+
000000000000000H00
4+
000000000000000000
5+
00000000H000000000
6+
000000000000000000
7+
000000000000000000
8+
000000000000000000
9+
000000HH0000000000
10+
000000000000000000
11+
000000000000000000
12+
000000000000000H00
13+
000000000000000000
14+
000000000000000000
15+
000000000000000000
16+
HHH00000000H000000
17+
000000000000000000
18+
000000000000000000
19+
000000000000000000
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
22
2+
0000000000000000000000
3+
0000000000000000000000
4+
0000000AAHAA0000000000
5+
0000000000000000000000
6+
0000000000000000000000
7+
000000000000000000000A
8+
0000000000000000000000
9+
0000000000000000000000
10+
000A000000000000000000
11+
000000000HAH0000A00000
12+
0000000000000000000000
13+
A000000000000000000000
14+
A000000000000000000000
15+
0000000000000000000000
16+
0000000000000000000000
17+
0000000000000000000000
18+
A000000000000000000H00
19+
0000000000000000000000
20+
0000000000A00000000000
21+
0000000000000000000000
22+
0000000000000000000000
23+
H00000000000000000000A
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
22
2+
000000000000000000000A
3+
00000B0000000000000000
4+
0000000000000000000000
5+
0B0000000000000000000B
6+
000000000000000000B000
7+
0000000000000000000000
8+
000000000000000000000B
9+
0000000000000000000000
10+
000000B00000000A000000
11+
000000000000000000000B
12+
0000000000000000000000
13+
000000B000000000000000
14+
000000000000000000000B
15+
0000000000000000000000
16+
000000000H000000000000
17+
000000000000000000000B
18+
0000000000000000000000
19+
A000000000000000000000
20+
A00000000000B000000000
21+
A000000000000000000000
22+
HHHH00000000000000A00H
23+
00000000A0000000000000
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
00000
3+
00000
4+
00A00
5+
00000
6+
00000
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
25
2+
0000000000000000000000000
3+
00000000000HHH00000000H00
4+
00H0000000000000000000000
5+
0000000000000000000000000
6+
0000000000000000000000000
7+
00000000000000000000A0000
8+
000000000000000B000000000
9+
00000H0000A00000000000000
10+
00000000000000000000H0000
11+
0000000000000000000000000
12+
0000000000000000000000000
13+
00A0000000000000000000000
14+
0000000000000000000000000
15+
00000B0000000000000000000
16+
0000000000000000000000000
17+
0000000000000000000A00000
18+
00000B00BBB00000000000000
19+
0000000000000000000000000
20+
0A00000000000000000000000
21+
0000000000000000000000000
22+
0000000000000000000000000
23+
000000000000A000000000000
24+
0000000000000000000000000
25+
000B000000000000000000000
26+
000000000000000000000H000
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
15
2+
A07000000000000
3+
007000070000000
4+
777003009000000
5+
00000000000000A
6+
000000000000000
7+
000000000000000
8+
004000009000000
9+
0000A00H0000000
10+
006000000000000
11+
000000080000000
12+
A00000000000000
13+
000000000000000
14+
000000000000030
15+
000000000000000
16+
00100000H000000

0 commit comments

Comments
 (0)