Skip to content

Commit 25b0e1f

Browse files
committed
Adding tests for "Reverse Minesweeper".
1 parent fbf3711 commit 25b0e1f

File tree

11 files changed

+189
-0
lines changed

11 files changed

+189
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Tests for "Sudoku validator".
2222
- Tests for "Mountain map".
2323
- Tests for "Create the longest sequence of 1s".
24+
- Tests for "Reverse Minesweeper".
2425

2526
## [3.6.0] - 2022-03-11
2627
### Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\ReverseMinesweeper;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Reverse Minesweeper" puzzle.
11+
*/
12+
class ReverseMinesweeper implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $w);
17+
fscanf($stdin, "%d", $h);
18+
for ($i = 0; $i < $h; $i++)
19+
{
20+
$line = stream_get_line($stdin, 100 + 1, "\n");
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("answer\n");
26+
}
27+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\ReverseMinesweeper;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\ReverseMinesweeper\ReverseMinesweeper;
9+
10+
/**
11+
* Tests for the "Reverse Minesweeper" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\ReverseMinesweeper\ReverseMinesweeper
14+
* @group reverseMinesweeper
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new ReverseMinesweeper();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "One mine".
26+
*
27+
* @group reverseMinesweeper_oneMine
28+
*/
29+
public function testCanExecuteOneMine(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - one mine.txt',
33+
file_get_contents(__DIR__ . '/output/01 - one mine.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Many mines".
39+
*
40+
* @group reverseMinesweeper_manyMines
41+
*/
42+
public function testCanExecuteManyMines(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - many mines.txt',
46+
file_get_contents(__DIR__ . '/output/02 - many mines.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Lot of mines".
52+
*
53+
* @group reverseMinesweeper_lotOfMines
54+
*/
55+
public function testCanExecuteLotOfMines(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - lot of mines.txt',
59+
file_get_contents(__DIR__ . '/output/03 - lot of mines.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "No mine".
65+
*
66+
* @group reverseMinesweeper_noMine
67+
*/
68+
public function testCanExecuteNoMine(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - no mine.txt',
72+
file_get_contents(__DIR__ . '/output/04 - no mine.txt')
73+
);
74+
}
75+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
16
2+
9
3+
................
4+
................
5+
................
6+
................
7+
................
8+
....x...........
9+
................
10+
................
11+
................
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
10
2+
7
3+
..........
4+
.x...x...x
5+
..x......x
6+
.....x....
7+
..x.x...x.
8+
x.........
9+
.x...x...x
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
16
2+
11
3+
..xxxxxx..x.x...
4+
.xx...xxx....xxx
5+
x.xxxx.xxx...xxx
6+
xxxxxxxxxx..xxxx
7+
...xx..x..xxxx..
8+
xx.xx.xxxx..x...
9+
xxxxxx.....x..xx
10+
xx......xxx..xxx
11+
xxxxxxxxxxxxxxxx
12+
xxx.xxx......xx.
13+
........xxxxxxxx
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
26
2+
12
3+
..........................
4+
..........................
5+
..........................
6+
..........................
7+
..........................
8+
..........................
9+
..........................
10+
..........................
11+
..........................
12+
..........................
13+
..........................
14+
..........................
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
................
2+
................
3+
................
4+
................
5+
...111..........
6+
...1.1..........
7+
...111..........
8+
................
9+
................
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
111.111.11
2+
1.211.1.2.
3+
12.1222.2.
4+
.2232.1122
5+
12.2.211.1
6+
.322221122
7+
2.1.1.1.1.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
13......32.2.332
2+
2..766...4223...
3+
.7....7...214...
4+
..........44....
5+
456..66.75....42
6+
..6..5....45.432
7+
......34554.34..
8+
..766544...55...
9+
................
10+
...5...556667..5
11+
23222322........

0 commit comments

Comments
 (0)