Skip to content

Commit b02d9b8

Browse files
committed
Adding tests for "Fax machine".
1 parent 7a19db8 commit b02d9b8

File tree

13 files changed

+163
-0
lines changed

13 files changed

+163
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Tests for "1000000000D world".
1010
- Tests for "Rooks movements".
1111
- Tests for "Jack Silver: the casino".
12+
- Tests for "Fax machine".
1213

1314
## [3.4.0] - 2022-02-21
1415
### 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\FaxMachine;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Fax machine" puzzle.
11+
*/
12+
class FaxMachine implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $W);
17+
fscanf($stdin, "%d", $H);
18+
$T = stream_get_line($stdin, 1024 + 1, "\n");
19+
20+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
21+
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
22+
23+
echo("|********|\n");
24+
echo("|** |\n");
25+
echo("| ****|\n");
26+
}
27+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\FaxMachine;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\FaxMachine\FaxMachine;
9+
10+
/**
11+
* Tests for the "Fax machine" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\FaxMachine\FaxMachine
14+
* @group faxMachine
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new FaxMachine();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "The example".
26+
*
27+
* @group faxMachine_theExample
28+
*/
29+
public function testCanExecuteTheExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - the example.txt',
33+
file_get_contents(__DIR__ . '/output/01 - the example.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Half black half white".
39+
*
40+
* @group faxMachine_halfBlackHalfWhite
41+
*/
42+
public function testCanExecuteHalfBlackHalfWhite(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - half black half white.txt',
46+
file_get_contents(__DIR__ . '/output/02 - half black half white.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Hello".
52+
*
53+
* @group faxMachine_hello
54+
*/
55+
public function testCanExecuteHello(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - hello.txt',
59+
file_get_contents(__DIR__ . '/output/03 - hello.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Heart".
65+
*
66+
* @group faxMachine_heart
67+
*/
68+
public function testCanExecuteHeart(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - heart.txt',
72+
file_get_contents(__DIR__ . '/output/04 - heart.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Inverse".
78+
*
79+
* @group faxMachine_inverse
80+
*/
81+
public function testCanExecuteInverse(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - inverse.txt',
85+
file_get_contents(__DIR__ . '/output/05 - inverse.txt')
86+
);
87+
}
88+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
8
2+
3
3+
10 10 4
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
32
2+
6
3+
93 99
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
16
2+
9
3+
16 18 2 2 2 3 2 5 2 2 2 10 6 3 2 5 2 2 2 3 2 5 2 2 2 3 2 19 16
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
23
2+
7
3+
6 4 3 4 11 6 1 6 11 11 13 9 16 6 18 4 20 2 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
23
2+
7
3+
0 6 4 3 4 11 6 1 6 11 11 13 9 16 6 18 4 20 2 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
|********|
2+
|** |
3+
| ****|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|********************************|
2+
|********************************|
3+
|***************************** |
4+
| |
5+
| |
6+
| |

0 commit comments

Comments
 (0)