Skip to content

Commit 99015dd

Browse files
committed
Adding tests for "CGX formatter".
1 parent 3126864 commit 99015dd

25 files changed

+678
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "Blunder - episode 2".
10+
- Tests for "CGX formatter".
1011

1112
## [2.3.0] - 2022-02-11
1213
### Added
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Hard\CGXFormatter;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "CGX formatter" puzzle.
11+
*/
12+
class CGXFormatter implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
$cgxLine = stream_get_line($stdin, 1000 + 1, "\n");
20+
}
21+
22+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
23+
24+
echo("answer\n");
25+
}
26+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Hard\CGXFormatter;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Hard\CGXFormatter\CGXFormatter;
9+
10+
/**
11+
* Tests for the "CGX formatter" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Hard\CGXFormatter\CGXFormatter
14+
* @group CGXFormatter
15+
*/
16+
final class CGXFormatterTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new CGXFormatter();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Boolean value with spaces and tabs".
25+
*
26+
* @group CGXFormatter_booleanValueWithSpacesAndTabs
27+
*/
28+
public function testCanExecuteBooleanValueWithSpacesAndTabs(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - boolean value with spaces and tabs.txt',
32+
'true'
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "Simple string of characters which must not be modified".
38+
*
39+
* @group CGXFormatter_simpleStringOfCharactersWhichMustNotBeModified
40+
*/
41+
public function testCanExecuteSimpleStringOfCharactersWhichMustNotBeModified(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - simple string of characters which must not be modified.txt',
45+
"' Content with spaces and tabs'"
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "Block containing a single value".
51+
*
52+
* @group CGXFormatter_blockContainingASingleValue
53+
*/
54+
public function testCanExecuteBlockContainingASingleValue(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - block containing a single value.txt',
58+
file_get_contents(__DIR__ . '/output/03 - block containing a single value.txt')
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Block containing a multiple values".
64+
*
65+
* @group CGXFormatter_blockContainingMultipleValues
66+
*/
67+
public function testCanExecuteBlockContainingMultipleValues(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - block containing a multiple values.txt',
71+
file_get_contents(__DIR__ . '/output/04 - block containing a multiple values.txt')
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Nested blocks".
77+
*
78+
* @group CGXFormatter_nestedBlocks
79+
*/
80+
public function testCanExecuteNestedBlocks(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - nested blocks.txt',
84+
file_get_contents(__DIR__ . '/output/05 - nested blocks.txt')
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Empty block".
90+
*
91+
* @group CGXFormatter_emptyBlock
92+
*/
93+
public function testCanExecuteEmptyBlock(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - empty block.txt',
97+
file_get_contents(__DIR__ . '/output/06 - empty block.txt')
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Block containing several blocks".
103+
*
104+
* @group CGXFormatter_blockContainingSeveralBlocks
105+
*/
106+
public function testCanExecuteBlockContainingSeveralBlocks(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - block containing several blocks.txt',
110+
file_get_contents(__DIR__ . '/output/07 - block containing several blocks.txt')
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "Key/value without blanks".
116+
*
117+
* @group CGXFormatter_keyValueWithoutBlanks
118+
*/
119+
public function testCanExecuteKeyValueWithoutBlanks(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - key value without blanks.txt',
123+
file_get_contents(__DIR__ . '/output/08 - key value without blanks.txt')
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Block with several key/value".
129+
*
130+
* @group CGXFormatter_blockWithSeveralKeyValue
131+
*/
132+
public function testCanExecuteBlockWithSeveralKeyValue(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - block with several key value.txt',
136+
file_get_contents(__DIR__ . '/output/09 - block with several key value.txt')
137+
);
138+
}
139+
140+
/**
141+
* Test that the code can be executed for "Example provided".
142+
*
143+
* @group CGXFormatter_exampleProvided
144+
*/
145+
public function testCanExecuteExampleProvided(): void
146+
{
147+
$this->expectExecuteOutputAnswer(
148+
__DIR__ . '/input/10 - example provided.txt',
149+
file_get_contents(__DIR__ . '/output/10 - example provided.txt')
150+
);
151+
}
152+
153+
/**
154+
* Test that the code can be executed for "Full example".
155+
*
156+
* @group CGXFormatter_fullExample
157+
*/
158+
public function testCanExecuteFullExample(): void
159+
{
160+
$this->expectExecuteOutputAnswer(
161+
__DIR__ . '/input/11 - full example.txt',
162+
file_get_contents(__DIR__ . '/output/11 - full example.txt')
163+
);
164+
}
165+
166+
/**
167+
* Test that the code can be executed for "Numerous overlaps".
168+
*
169+
* @group CGXFormatter_numerousOverlaps
170+
*/
171+
public function testCanExecuteNumerousOverlaps(): void
172+
{
173+
$this->expectExecuteOutputAnswer(
174+
__DIR__ . '/input/12 - numerous overlaps.txt',
175+
file_get_contents(__DIR__ . '/output/12 - numerous overlaps.txt')
176+
);
177+
}
178+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
3+
4+
true
5+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
' Content with spaces and tabs'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
(0)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
(0;1;2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
((true))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
((true);(false);(0))

0 commit comments

Comments
 (0)