Skip to content

Commit 3eef8ef

Browse files
committed
Adding tests for "Binary image".
1 parent 46454e7 commit 3eef8ef

File tree

16 files changed

+221
-0
lines changed

16 files changed

+221
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Tests for "Equivalent resistance, circuit building".
1313
- Tests for "1D spreadsheet".
1414
- Tests for "Ghost legs".
15+
- Tests for "Binary image".
1516

1617
### Changed
1718
- "STDIN" to "$stdin" in the "Rock paper scissors lizard spock" default code.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\BinaryImage;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Binary image" puzzle.
11+
*/
12+
class BinaryImage implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $h);
17+
for ($i = 0; $i < $h; $i++)
18+
{
19+
$row = stream_get_line($stdin, 200 + 1, "\n");
20+
}
21+
for ($i = 0; $i < $h; $i++)
22+
{
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("answer\n");
27+
}
28+
}
29+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\BinaryImage;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\BinaryImage\BinaryImage;
9+
10+
/**
11+
* Tests for the "Binary image" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\BinaryImage\BinaryImage
14+
* @group binaryImage
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new BinaryImage();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Vertical stripes".
26+
*
27+
* @group binaryImage_verticalStripes
28+
*/
29+
public function testCanExecuteVerticalStripes(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - vertical stripes.txt',
33+
file_get_contents(__DIR__ . '/output/01 - vertical stripes.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Starting by 0".
39+
*
40+
* @group binaryImage_startingBy0
41+
*/
42+
public function testCanExecuteStartingBy0(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - starting by 0.txt',
46+
file_get_contents(__DIR__ . '/output/02 - starting by 0.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Chess board".
52+
*
53+
* @group binaryImage_chessBoard
54+
*/
55+
public function testCanExecuteChessBoard(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - chess board.txt',
59+
file_get_contents(__DIR__ . '/output/03 - chess board.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Horizontal stripes".
65+
*
66+
* @group binaryImage_horizontalStripes
67+
*/
68+
public function testCanExecuteHorizontalStripes(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - horizontal stripes.txt',
72+
file_get_contents(__DIR__ . '/output/04 - horizontal stripes.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Codingame".
78+
*
79+
* @group binaryImage_codingame
80+
*/
81+
public function testCanExecuteCodingame(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - codingame.txt',
85+
file_get_contents(__DIR__ . '/output/05 - codingame.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Invalid".
91+
*
92+
* @group binaryImage_invalid
93+
*/
94+
public function testCanExecuteInvalid(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - invalid.txt',
98+
'INVALID' . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Random".
104+
*
105+
* @group binaryImage_random
106+
*/
107+
public function testCanExecuteRandom(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - random.txt',
111+
file_get_contents(__DIR__ . '/output/07 - random.txt')
112+
);
113+
}
114+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 3 2 1
3+
1 3 2 1
4+
1 3 2 1
5+
1 3 2 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
0 1 1 1 1
3+
0 1 1 1 1
4+
0 1 1 1 1
5+
0 1 1 1 1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
0 1 1 1 1 1 1 1 1
3+
1 1 1 1 1 1 1 1
4+
0 1 1 1 1 1 1 1 1
5+
1 1 1 1 1 1 1 1
6+
0 1 1 1 1 1 1 1 1
7+
1 1 1 1 1 1 1 1
8+
0 1 1 1 1 1 1 1 1
9+
1 1 1 1 1 1 1 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
8
3+
0 8
4+
8
5+
0 8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
45
3+
2 2 3 2 2 3 2 1 1 1 3 1 2 2 3 2 2 1 3 1 1 4 1
4+
1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 2 1 2 1 1 4
5+
1 1 4 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 4 1 2 1 1 1 1 1 1 1 1 3 2
6+
1 1 4 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 4 1 1 3 1 1 1 4
7+
1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 3 1 1 1 2 1 1 1 2 1 1 1 3 1 1 1 4
8+
2 2 3 2 2 3 2 1 1 1 3 1 2 2 2 1 2 1 1 1 3 1 1 4 1
9+
45
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
0 1 1 2
3+
0 2 1 1
4+
0 1 1 1
5+
1 1 1 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
0 1 2 1 1 1 2 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 3 1 2
3+
2 3 1 1 6 1 1 1 1 1 2 2 2 1 1 1 4 1 1 1 3 2 1 2 1 1 1 1 3 1
4+
1 1 3 5 2 3 1 2 1 3 2 2 2 3 1 2 4 2 4 5 1
5+
0 1 1 1 1 3 3 1 1 2 2 2 2 1 1 3 1 1 2 1 1 2 2 1 3 1 1 1 2 4 1 1
6+
2 2 1 1 1 3 1 1 2 1 6 1 1 4 1 1 2 1 1 1 1 1 1 1 2 2 3 1 4

0 commit comments

Comments
 (0)