Skip to content

Commit 9d81fe2

Browse files
committed
Adding tests for "Minesweeper level
generator".
1 parent dc1deb6 commit 9d81fe2

File tree

15 files changed

+192
-0
lines changed

15 files changed

+192
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Tests for "Park pilot".
3131
- Tests for "Buzzle".
3232
- Tests for "How time flies".
33+
- Tests for "Minesweeper level generator".
3334

3435
### Changed
3536
- Renaming "Linear Bézier curves" to "Cubic Bézier curves".
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\MinesweeperLevelGenerator;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Minesweeper level generator" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/minesweeper-level-generator
12+
*/
13+
class MinesweeperLevelGenerator implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d %d %d %d %d", $width, $height, $mines, $x, $y, $seed);
18+
for ($i = 0; $i < $height; $i++)
19+
{
20+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
21+
22+
echo("row\n");
23+
}
24+
}
25+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\MinesweeperLevelGenerator;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\MinesweeperLevelGenerator\MinesweeperLevelGenerator;
9+
10+
/**
11+
* Tests for the "Minesweeper level generator" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\MinesweeperLevelGenerator\MinesweeperLevelGenerator
14+
* @group minesweeperLevelGenerator
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new MinesweeperLevelGenerator();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Simple level".
26+
*
27+
* @group minesweeperLevelGenerator_simpleLevel
28+
*/
29+
public function testCanExecuteTest1(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - simple level.txt',
33+
file_get_contents(__DIR__ . '/output/01 - simple level.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Corner selection".
39+
*
40+
* @group minesweeperLevelGenerator_cornerSelection
41+
*/
42+
public function testCanExecuteCornerSelection(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - corner selection.txt',
46+
file_get_contents(__DIR__ . '/output/02 - corner selection.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Edge selection".
52+
*
53+
* @group minesweeperLevelGenerator_edgeSelection
54+
*/
55+
public function testCanExecuteEdgeSelection(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - edge selection.txt',
59+
file_get_contents(__DIR__ . '/output/03 - edge selection.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Beginner level".
65+
*
66+
* @group minesweeperLevelGenerator_beginnerLevel
67+
*/
68+
public function testCanExecuteBeginnerLevel(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - beginner level.txt',
72+
file_get_contents(__DIR__ . '/output/04 - beginner level.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Intermediate level".
78+
*
79+
* @group minesweeperLevelGenerator_intermediateLevel
80+
*/
81+
public function testCanExecuteIntermediateLevel(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - intermediate level.txt',
85+
file_get_contents(__DIR__ . '/output/05 - intermediate level.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Expert level".
91+
*
92+
* @group minesweeperLevelGenerator_expertLevel
93+
*/
94+
public function testCanExecuteExpertLevel(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - expert level.txt',
98+
file_get_contents(__DIR__ . '/output/06 - expert level.txt')
99+
);
100+
}
101+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6 6 7 3 3 31
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6 6 6 0 0 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6 6 6 2 0 31
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9 9 10 4 4 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16 16 40 8 8 17
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
30 16 99 15 8 17
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1#2##1
2+
222221
3+
#1..11
4+
331.1#
5+
##1.11
6+
221...

0 commit comments

Comments
 (0)