Skip to content

Commit a5fa69e

Browse files
committed
Adding tests for "Snake encoding".
1 parent 2b9e673 commit a5fa69e

File tree

11 files changed

+162
-0
lines changed

11 files changed

+162
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Tests for "Magic stones".
3232
- Tests for "Game of life".
3333
- Tests for "Maximum sub-sequence".
34+
- Tests for "Snake encoding".
3435

3536
## [3.13.0] - 2022-09-30
3637
### 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\Medium\SnakeEncoding;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Snake encoding" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/snake-encoding
12+
*/
13+
class SnakeEncoding implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
fscanf($stdin, "%d", $X);
19+
for ($i = 0; $i < $N; $i++)
20+
{
21+
fscanf($stdin, "%s", $LINE);
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("answer\n");
27+
}
28+
}
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\Medium\SnakeEncoding;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\SnakeEncoding\SnakeEncoding;
9+
10+
/**
11+
* Tests for the "Snake encoding" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\SnakeEncoding\SnakeEncoding
14+
* @group snakeEncoding
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SnakeEncoding();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Easy peasy".
26+
*
27+
* @group snakeEncoding_easyPeasy
28+
*/
29+
public function testCanExecuteEasyPeasy(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - easy peasy.txt',
33+
file_get_contents(__DIR__ . '/output/01 - easy peasy.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "More rows".
39+
*
40+
* @group snakeEncoding_moreRows
41+
*/
42+
public function testCanExecuteMoreRows(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - more rows.txt',
46+
file_get_contents(__DIR__ . '/output/02 - more rows.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "More loops".
52+
*
53+
* @group snakeEncoding_moreLoops
54+
*/
55+
public function testCanExecuteMoreLoops(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - more loops.txt',
59+
file_get_contents(__DIR__ . '/output/03 - more loops.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Let's try everything".
65+
*
66+
* @group snakeEncoding_letsTryEverything
67+
*/
68+
public function testCanExecuteLetsTryEverything(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - let\'s try everything.txt',
72+
file_get_contents(__DIR__ . '/output/04 - let\'s try everything.txt')
73+
);
74+
}
75+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
1
3+
ABC
4+
DEF
5+
GHI
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
5
2+
1
3+
ABCDE
4+
FGHIJ
5+
KLMNO
6+
PQRST
7+
UVWXY
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
7
2+
5
3+
I_LOVE_
4+
TESTING
5+
AMAZING
6+
ENCODES
7+
NOTYOU?
8+
NUM83R5
9+
NICE:)!
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
10
2+
38
3+
PN_OOEITH_
4+
_THYSNLIKM
5+
LRNIEGC'A_
6+
_CVDR!IO'E
7+
!E!Y!U9_0O
8+
OT_IO_RINE
9+
>EAGE!BHEL
10+
NO_E__ITWS
11+
A!T!A!Z0_0
12+
RMWRTWRAED
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DAF
2+
GBI
3+
CEH
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FAHCJ
2+
KBMDO
3+
PGRIT
4+
ULWNY
5+
EQVSX
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NNMT3O5
2+
NECC:D!
3+
_AIAEI)
4+
GTUS8IR
5+
GIOLYVU
6+
S_NOOEE
7+
?EMTZNN

0 commit comments

Comments
 (0)