Skip to content

Commit dbd9be5

Browse files
committed
Adding tests for "Snail run".
1 parent d06ca29 commit dbd9be5

File tree

11 files changed

+240
-0
lines changed

11 files changed

+240
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Tests for "Simple load balancing".
3333
- Tests for "Are the clumps normal".
3434
- Tests for "Bulk email generator".
35+
- Tests for "Snail run".
3536

3637
## [3.8.0] - 2022-04-30
3738
### Added
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\SnailRun;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Snail run" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/snail-run
12+
*/
13+
class SnailRun implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $numberSnails);
18+
for ($i = 0; $i < $numberSnails; $i++)
19+
{
20+
fscanf($stdin, "%d", $speedSnail);
21+
}
22+
fscanf($stdin, "%d", $mapHeight);
23+
fscanf($stdin, "%d", $mapWidth);
24+
for ($i = 0; $i < $mapHeight; $i++)
25+
{
26+
$ROW = stream_get_line($stdin, 1024 + 1, "\n");
27+
}
28+
29+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
30+
31+
echo("winner is number\n");
32+
}
33+
}
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\SnailRun;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\SnailRun\SnailRun;
9+
10+
/**
11+
* Tests for the "Snail run" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\SnailRun\SnailRun
14+
* @group snailRun
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SnailRun();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Simple run".
26+
*
27+
* @group snailRun_simpleRun
28+
*/
29+
public function testCanExecuteSimpleRun(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - simple run.txt',
33+
3 . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Run in progress".
39+
*
40+
* @group snailRun_runInProgress
41+
*/
42+
public function testCanExecuteRunInProgress(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - run in progress.txt',
46+
3 . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Only one arrives".
52+
*
53+
* @group snailRun_onlyOneArrives
54+
*/
55+
public function testCanExecuteOnlyOneArrives(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - only one arrives.txt',
59+
1 . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "In a mess".
65+
*
66+
* @group snailRun_inAMess
67+
*/
68+
public function testCanExecuteInAMess(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - in a mess.txt',
72+
3 . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Conversely".
78+
*
79+
* @group snailRun_conversely
80+
*/
81+
public function testCanExecuteConversely(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - conversely.txt',
85+
3 . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Difficult 1".
91+
*
92+
* @group snailRun_difficult1
93+
*/
94+
public function testCanExecuteDifficult1(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - difficult 1.txt',
98+
3 . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Difficult 2".
104+
*
105+
* @group snailRun_difficult2
106+
*/
107+
public function testCanExecuteDifficult2(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - difficult 2.txt',
111+
3 . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Difficult 3".
117+
*
118+
* @group snailRun_difficult3
119+
*/
120+
public function testCanExecuteDifficult3(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - difficult 3.txt',
124+
2 . PHP_EOL
125+
);
126+
}
127+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
2
3+
3
4+
5
5+
3
6+
6
7+
1****#
8+
2****#
9+
3****#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
4
2+
1
3+
3
4+
4
5+
1
6+
4
7+
6
8+
**1**#
9+
*2***#
10+
**3**#
11+
**4**#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
3
3+
1
4+
2
5+
3
6+
8
7+
1*******
8+
2******#
9+
3*******
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
4
3+
2
4+
2
5+
3
6+
7
7+
12****3
8+
*******
9+
******#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
5
2+
1
3+
1
4+
2
5+
1
6+
1
7+
5
8+
7
9+
#*****1
10+
#*****2
11+
#*****3
12+
#*****4
13+
#*****5
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3
2+
1
3+
1
4+
1
5+
3
6+
7
7+
**3****
8+
****2**
9+
#*****1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
4
2+
1
3+
1
4+
1
5+
1
6+
4
7+
7
8+
1******
9+
****3**
10+
**#***2
11+
******4

0 commit comments

Comments
 (0)