Skip to content

Commit c50428d

Browse files
committed
Adding tests for "Surface".
1 parent 99015dd commit c50428d

19 files changed

+2145
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [2.4.0] - 2022-02-11
88
### Added
99
- Tests for "Blunder - episode 2".
1010
- Tests for "CGX formatter".
11+
- Tests for "Surface".
1112

1213
## [2.3.0] - 2022-02-11
1314
### Added
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Hard\Surface;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Surface" puzzle.
11+
*/
12+
class Surface implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $L);
17+
fscanf($stdin, "%d", $H);
18+
for ($i = 0; $i < $H; $i++)
19+
{
20+
$row = stream_get_line($stdin, $L + 1, "\n");
21+
}
22+
fscanf($stdin, "%d", $N);
23+
for ($i = 0; $i < $N; $i++)
24+
{
25+
fscanf($stdin, "%d %d", $X, $Y);
26+
}
27+
for ($i = 0; $i < $N; $i++)
28+
{
29+
30+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
31+
32+
echo("answer\n");
33+
}
34+
}
35+
}
+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Hard\Surface;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Hard\Surface\Surface;
9+
10+
/**
11+
* Tests for the "Surface" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Hard\Surface\Surface
14+
* @group surface
15+
*/
16+
final class SurfaceTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new Surface();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Example of the statement".
25+
*
26+
* @group surface_exampleOfTheStatement
27+
*/
28+
public function testCanExecuteExampleOfTheStatement(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - example of the statement.txt',
32+
file_get_contents(__DIR__ . '/output/01 - example of the statement.txt')
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "No lake".
38+
*
39+
* @group surface_noLake
40+
*/
41+
public function testCanExecuteNoLake(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - no lake.txt',
45+
0 . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "The area is a lake".
51+
*
52+
* @group surface_theAreaIsALake
53+
*/
54+
public function testCanExecuteTheAreaIsALake(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - the area is a lake.txt',
58+
file_get_contents(__DIR__ . '/output/03 - the area is a lake.txt')
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "1 lake on a small map".
64+
*
65+
* @group surface_1LakeOnASmallMap
66+
*/
67+
public function testCanExecute1LakeOnASmallMap(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - 1 lake on a small map.txt',
71+
file_get_contents(__DIR__ . '/output/04 - 1 lake on a small map.txt')
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Several lakes on a small map".
77+
*
78+
* @group surface_severalLakesOnASmallMap
79+
*/
80+
public function testCanExecuteSeveralLakesOnASmallMap(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - several lakes on a small map.txt',
84+
file_get_contents(__DIR__ . '/output/05 - several lakes on a small map.txt')
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Some lakes on a 20x20 map".
90+
*
91+
* @group surface_someLakesOnA20x20Map
92+
*/
93+
public function testCanExecuteSomeLakesOnA20x20Map(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - some lakes on a 20x20 map.txt',
97+
file_get_contents(__DIR__ . '/output/06 - some lakes on a 20x20 map.txt')
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Many lakes on a 100x50 map".
103+
*
104+
* @group surface_manyLakesOnA100x50Map
105+
*/
106+
public function testCanExecuteManyLakesOnA100x50Map(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - many lakes on a 100x50 map.txt',
110+
file_get_contents(__DIR__ . '/output/07 - many lakes on a 100x50 map.txt')
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "100 tests on a 1000x1000 map".
116+
*
117+
* @group surface_100TestsOnA1000x1000Map
118+
*/
119+
public function testCanExecute100TestsOnA1000x1000Map(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - 100 tests on a 1000x1000 map.txt',
123+
file_get_contents(__DIR__ . '/output/08 - 100 tests on a 1000x1000 map.txt')
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Large map, large lake".
129+
*
130+
* @group surface_largeMapLargeLake
131+
*/
132+
public function testCanExecuteLargeMapLargeLake(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - large map, large lake.txt',
136+
359997 . PHP_EOL
137+
);
138+
}
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
4
2+
4
3+
####
4+
##O#
5+
#OO#
6+
####
7+
3
8+
0 0
9+
1 2
10+
2 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1
2+
1
3+
#
4+
1
5+
0 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
3
3+
OOO
4+
OOO
5+
OOO
6+
3
7+
0 0
8+
1 1
9+
2 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
4
2+
4
3+
####
4+
#OO#
5+
#OO#
6+
####
7+
5
8+
0 0
9+
1 1
10+
2 1
11+
3 3
12+
1 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
6
2+
6
3+
OO###O
4+
#O###O
5+
#OO##O
6+
####O#
7+
##OO##
8+
##OO##
9+
5
10+
1 0
11+
3 3
12+
5 1
13+
0 5
14+
2 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
20
2+
20
3+
########OOOO#OOO####
4+
########OOOOOO######
5+
########OO##########
6+
########OO##########
7+
#######OOO##########
8+
#################O##
9+
#################O##
10+
######OOO######OOO##
11+
######OOOO####OOOO##
12+
##############OOOOO#
13+
##############OOO#OO
14+
##############OOOOOO
15+
#############OOOO###
16+
####################
17+
####################
18+
#####OO#############
19+
####################
20+
####################
21+
####################
22+
##############OOOOO#
23+
10
24+
8 2
25+
8 7
26+
6 15
27+
16 7
28+
6 7
29+
16 7
30+
14 19
31+
18 19
32+
16 7
33+
15 9

0 commit comments

Comments
 (0)