Skip to content

Commit 7eace5a

Browse files
committed
Adding tests for "Advanced tree".
1 parent c276710 commit 7eace5a

39 files changed

+699
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Vote counting".
3737
- Tests for "Maze for the champions".
3838
- Tests for "Longest increasing subsequence".
39+
- Tests for "Advanced tree".
3940

4041
## [3.16.0] - 2022-12-31
4142
### Added
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\Medium\AdvancedTree;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Advanced tree" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/advanced-tree
12+
*/
13+
class AdvancedTree implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
$S = stream_get_line($stdin, 512 + 1, "\n");
18+
$F = stream_get_line($stdin, 512 + 1, "\n");
19+
fscanf($stdin, "%d", $N);
20+
for ($i = 0; $i < $N; $i++)
21+
{
22+
$line = stream_get_line($stdin, 512 + 1, "\n");
23+
}
24+
25+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
26+
27+
echo("Tree output\n");
28+
}
29+
}
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\AdvancedTree;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\AdvancedTree\AdvancedTree;
9+
10+
/**
11+
* Tests for the "Advanced tree" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\AdvancedTree\AdvancedTree
14+
* @group advancedTree
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new AdvancedTree();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example".
26+
*
27+
* @group advancedTree_example
28+
*/
29+
public function testCanExecuteExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example.txt',
33+
file_get_contents(__DIR__ . '/output/01 - example.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "In a directory test".
39+
*
40+
* @group advancedTree_inADirectoryTest
41+
*/
42+
public function testCanExecuteInADirectoryTest(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - in a directory test.txt',
46+
file_get_contents(__DIR__ . '/output/02 - in a directory test.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Also in a directory test".
52+
*
53+
* @group advancedTree_alsoInADirectoryTest
54+
*/
55+
public function testCanExecuteAlsoInADirectoryTest(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - also in a directory test.txt',
59+
file_get_contents(__DIR__ . '/output/03 - also in a directory test.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Gap end of tree handling test".
65+
*
66+
* @group advancedTree_gapEndOfTreeHandlingTest
67+
*/
68+
public function testCanExecuteGapEndOfTreeHandlingTest(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - gap end of tree handling test.txt',
72+
file_get_contents(__DIR__ . '/output/04 - gap end of tree handling test.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Hidden directories w/o -a test".
78+
*
79+
* @group advancedTree_hiddenDirectoriesWOATest
80+
*/
81+
public function testCanExecuteHiddenDirectoriesWOATest(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - hidden directories wo -a test.txt',
85+
file_get_contents(__DIR__ . '/output/05 - hidden directories wo -a test.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Dots in filenames test".
91+
*
92+
* @group advancedTree_dotsInFilenamesTest
93+
*/
94+
public function testCanExecuteDotsInFilenamesTest(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - dots in filenames test.txt',
98+
file_get_contents(__DIR__ . '/output/06 - dots in filenames test.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Limit flag test".
104+
*
105+
* @group advancedTree_limitFlagTest
106+
*/
107+
public function testCanExecuteLimitFlagTest(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - limit flag test.txt',
111+
file_get_contents(__DIR__ . '/output/07 - limit flag test.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Hidden files w/o -a test".
117+
*
118+
* @group advancedTree_hiddenFilesWOATest
119+
*/
120+
public function testCanExecuteHiddenFilesWOATest(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - hidden files wo -a test.txt',
124+
file_get_contents(__DIR__ . '/output/08 - hidden files wo -a test.txt')
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Hidden files with -a test".
130+
*
131+
* @group advancedTree_hiddenFilesWithATest
132+
*/
133+
public function testCanExecuteHiddenFilesWithATest(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - hidden files with -a test.txt',
137+
file_get_contents(__DIR__ . '/output/09 - hidden files with -a test.txt')
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "Directory flag test".
143+
*
144+
* @group advancedTree_directoryFlagTest
145+
*/
146+
public function testCanExecuteDirectoryFlagTest(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - directory flag test.txt',
150+
file_get_contents(__DIR__ . '/output/10 - directory flag test.txt')
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Multiple flags test".
156+
*
157+
* @group advancedTree_multipleFlagsTest
158+
*/
159+
public function testCanExecuteMultipleFlagsTest(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - multiple flags test.txt',
163+
file_get_contents(__DIR__ . '/output/11 - multiple flags test.txt')
164+
);
165+
}
166+
167+
/**
168+
* Test that the code can be executed for "All flags test".
169+
*
170+
* @group advancedTree_allFlagsTest
171+
*/
172+
public function testCanExecuteAllFlagsTest(): void
173+
{
174+
$this->expectExecuteOutputAnswer(
175+
__DIR__ . '/input/12 - all flags test.txt',
176+
file_get_contents(__DIR__ . '/output/12 - all flags test.txt')
177+
);
178+
}
179+
180+
/**
181+
* Test that the code can be executed for "Error handling 1 test".
182+
*
183+
* @group advancedTree_errorHandling1Test
184+
*/
185+
public function testCanExecuteErrorHandling1Test(): void
186+
{
187+
$this->expectExecuteOutputAnswer(
188+
__DIR__ . '/input/13 - error handling 1 test.txt',
189+
file_get_contents(__DIR__ . '/output/13 - error handling 1 test.txt')
190+
);
191+
}
192+
193+
/**
194+
* Test that the code can be executed for "Error handling 2 test".
195+
*
196+
* @group advancedTree_errorHandling2Test
197+
*/
198+
public function testCanExecuteErrorHandling2Test(): void
199+
{
200+
$this->expectExecuteOutputAnswer(
201+
__DIR__ . '/input/14 - error handling 2 test.txt',
202+
file_get_contents(__DIR__ . '/output/14 - error handling 2 test.txt')
203+
);
204+
}
205+
206+
/**
207+
* Test that the code can be executed for "Error handling 3 test".
208+
*
209+
* @group advancedTree_errorHandling3Test
210+
*/
211+
public function testCanExecuteErrorHandling3Test(): void
212+
{
213+
$this->expectExecuteOutputAnswer(
214+
__DIR__ . '/input/15 - error handling 3 test.txt',
215+
file_get_contents(__DIR__ . '/output/15 - error handling 3 test.txt')
216+
);
217+
}
218+
219+
/**
220+
* Test that the code can be executed for "Wrong flag test".
221+
*
222+
* @group advancedTree_wrongFlagTest
223+
*/
224+
public function testCanExecuteWrongFlagTest(): void
225+
{
226+
$this->expectExecuteOutputAnswer(
227+
__DIR__ . '/input/16 - wrong flag test.txt',
228+
file_get_contents(__DIR__ . '/output/16 - wrong flag test.txt')
229+
);
230+
}
231+
232+
/**
233+
* Test that the code can be executed for "Big test 1".
234+
*
235+
* @group advancedTree_bigTest1
236+
*/
237+
public function testCanExecuteBigTest1(): void
238+
{
239+
$this->expectExecuteOutputAnswer(
240+
__DIR__ . '/input/17 - big test 1.txt',
241+
file_get_contents(__DIR__ . '/output/17 - big test 1.txt')
242+
);
243+
}
244+
245+
/**
246+
* Test that the code can be executed for "Not starting in .".
247+
*
248+
* @group advancedTree_notStartingIn
249+
*/
250+
public function testCanExecuteNotStartingIn(): void
251+
{
252+
$this->expectExecuteOutputAnswer(
253+
__DIR__ . '/input/18 - not starting in.txt',
254+
file_get_contents(__DIR__ . '/output/18 - not starting in.txt')
255+
);
256+
}
257+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
./Directory1
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Directory1
2+
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.
2+
3+
10
4+
./Directory1/File1
5+
./Directory2/File2
6+
./Directory3/File4
7+
./Directory3/File3
8+
./Directory4/Directory5/File5
9+
./Directory4/Directory5/File6
10+
./Directory6/File7
11+
./Directory6/File8
12+
./Directory6/Test/File10
13+
./Directory6/Test/File9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.
2+
3+
7
4+
./Directory1/File1
5+
./Directory2/File2
6+
./Directory2/File3
7+
./.Directory3/File4
8+
./Directory4/File5
9+
./Directory4/File6
10+
./Directory4/.Directory5/File7
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.
2+
-a
3+
7
4+
./Directory1/File1.txt
5+
./Directory1/File2.js
6+
./Directory2/File3.rb
7+
./Directory2/File4.cpp
8+
./.Directory3/Directory4/.File5.c
9+
./.Directory3/Directory4/File6.py
10+
./File7
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.
2+
-L 2
3+
6
4+
./Directory1/File1
5+
./Directory1/File2
6+
./Directory2/File3
7+
./Directory1/File4
8+
./Directory2/Directory3/File5
9+
./File6

0 commit comments

Comments
 (0)