Skip to content

Commit 96977da

Browse files
committed
Adding tests for "Cards castle".
1 parent 3b445c3 commit 96977da

24 files changed

+459
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [3.14.0] - 2022-10-31
88
### Added
99
- Tests for "A-star exercise".
1010
- Tests for "Othello".
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Tests for "Binary search tree traversal".
3636
- Tests for "Gravity centrifuge".
3737
- Tests for "Identifying data structure".
38+
- Tests for "Cards castle".
3839

3940
## [3.13.0] - 2022-09-30
4041
### 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\Medium\CardsCastle;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Cards castle" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/cards-castle
12+
*/
13+
class CardsCastle implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $H);
18+
for ($i = 0; $i < $H; $i++)
19+
{
20+
$S = stream_get_line($stdin, 128 + 1, "\n");
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("UNSTABLE\n");
26+
}
27+
}
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\CardsCastle;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\CardsCastle\CardsCastle;
9+
10+
/**
11+
* Tests for the "Cards castle" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\CardsCastle\CardsCastle
14+
* @group cardsCastle
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new CardsCastle();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example".
26+
*
27+
* @group cardsCastle_example
28+
*/
29+
public function testCanExecuteExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example.txt',
33+
"STABLE" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Little castle".
39+
*
40+
* @group cardsCastle_littleCastle
41+
*/
42+
public function testCanExecuteLittleCastle(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - little castle.txt',
46+
"STABLE" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Little fallen castle".
52+
*
53+
* @group cardsCastle_littleFallenCastle
54+
*/
55+
public function testCanExecuteLittleFallenCastle(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - little fallen castle.txt',
59+
"UNSTABLE" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Fortress".
65+
*
66+
* @group cardsCastle_fortress
67+
*/
68+
public function testCanExecuteFortress(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - fortress.txt',
72+
"STABLE" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Fallen fortress".
78+
*
79+
* @group cardsCastle_fallenFortress
80+
*/
81+
public function testCanExecuteFallenFortress(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - fallen fortress.txt',
85+
"UNSTABLE" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Cards are missing ?".
91+
*
92+
* @group cardsCastle_cardsAreMissing
93+
*/
94+
public function testCanExecuteCardsAreMissing(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - cards are missing ?.txt',
98+
"STABLE" . PHP_EOL
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "A lot of cards are missing ?!".
104+
*
105+
* @group cardsCastle_aLotOfCardsAreMissing
106+
*/
107+
public function testCanExecuteALotOfCardsAreMissing(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - a lot of cards are missing ?!.txt',
111+
"STABLE" . PHP_EOL
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Unstable single card".
117+
*
118+
* @group cardsCastle_unstableSingleCard
119+
*/
120+
public function testCanExecuteUnstableSingleCard(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - unstable single card.txt',
124+
"UNSTABLE" . PHP_EOL
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Flying cards".
130+
*
131+
* @group cardsCastle_flyingCards
132+
*/
133+
public function testCanExecuteFlyingCards(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - flying cards.txt',
137+
"UNSTABLE" . PHP_EOL
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "Reversed cards".
143+
*
144+
* @group cardsCastle_reversedCards
145+
*/
146+
public function testCanExecuteReversedCards(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - reversed cards.txt',
150+
"UNSTABLE" . PHP_EOL
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Few floors".
156+
*
157+
* @group cardsCastle_fewFloors
158+
*/
159+
public function testCanExecuteFewFloors(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - few floors.txt',
163+
"STABLE" . PHP_EOL
164+
);
165+
}
166+
167+
/**
168+
* Test that the code can be executed for "On the gap".
169+
*
170+
* @group cardsCastle_onTheGap
171+
*/
172+
public function testCanExecuteOnTheGap(): void
173+
{
174+
$this->expectExecuteOutputAnswer(
175+
__DIR__ . '/input/12 - on the gap.txt',
176+
"UNSTABLE" . PHP_EOL
177+
);
178+
}
179+
180+
/**
181+
* Test that the code can be executed for "Starting on".
182+
*
183+
* @group cardsCastle_startingOn
184+
*/
185+
public function testCanExecuteStartingOn(): void
186+
{
187+
$this->expectExecuteOutputAnswer(
188+
__DIR__ . '/input/13 - starting on.txt',
189+
"STABLE" . PHP_EOL
190+
);
191+
}
192+
193+
/**
194+
* Test that the code can be executed for "Shifted".
195+
*
196+
* @group cardsCastle_shifted
197+
*/
198+
public function testCanExecuteShifted(): void
199+
{
200+
$this->expectExecuteOutputAnswer(
201+
__DIR__ . '/input/14 - shifted.txt',
202+
"STABLE" . PHP_EOL
203+
);
204+
}
205+
206+
/**
207+
* Test that the code can be executed for "Flying castle cards".
208+
*
209+
* @group cardsCastle_flyingCastleCards
210+
*/
211+
public function testCanExecuteFlyingCastleCards(): void
212+
{
213+
$this->expectExecuteOutputAnswer(
214+
__DIR__ . '/input/15 - flying castle cards.txt',
215+
"UNSTABLE" . PHP_EOL
216+
);
217+
}
218+
219+
/**
220+
* Test that the code can be executed for "Same card side by side".
221+
*
222+
* @group cardsCastle_sameCardSideBySide
223+
*/
224+
public function testCanExecuteSameCardSideBySide(): void
225+
{
226+
$this->expectExecuteOutputAnswer(
227+
__DIR__ . '/input/16 - same card side by side.txt',
228+
"UNSTABLE" . PHP_EOL
229+
);
230+
}
231+
232+
/**
233+
* Test that the code can be executed for "Same flying card side by side".
234+
*
235+
* @group cardsCastle_sameFlyingCardSideBySide
236+
*/
237+
public function testCanExecuteSameFlyingCardSideBySide(): void
238+
{
239+
$this->expectExecuteOutputAnswer(
240+
__DIR__ . '/input/17 - same flying card side by side.txt',
241+
"UNSTABLE" . PHP_EOL
242+
);
243+
}
244+
245+
/**
246+
* Test that the code can be executed for "Flying reversed card side by side".
247+
*
248+
* @group cardsCastle_flyingReversedCardSideBySide
249+
*/
250+
public function testCanExecuteFlyingReversedCardSideBySide(): void
251+
{
252+
$this->expectExecuteOutputAnswer(
253+
__DIR__ . '/input/18 - flying reversed card side by side.txt',
254+
"UNSTABLE" . PHP_EOL
255+
);
256+
}
257+
258+
/**
259+
* Test that the code can be executed for "The shifted unique one".
260+
*
261+
* @group cardsCastle_theShiftedUniqueOne
262+
*/
263+
public function testCanExecuteTheShiftedUniqueOne(): void
264+
{
265+
$this->expectExecuteOutputAnswer(
266+
__DIR__ . '/input/19 - the shifted unique one.txt',
267+
"STABLE" . PHP_EOL
268+
);
269+
}
270+
271+
/**
272+
* Test that the code can be executed for "Lost cards".
273+
*
274+
* @group cardsCastle_lostCards
275+
*/
276+
public function testCanExecuteLostCards(): void
277+
{
278+
$this->expectExecuteOutputAnswer(
279+
__DIR__ . '/input/20 - lost cards.txt',
280+
"STABLE" . PHP_EOL
281+
);
282+
}
283+
284+
/**
285+
* Test that the code can be executed for "Complex".
286+
*
287+
* @group cardsCastle_complex
288+
*/
289+
public function testCanExecuteComplex(): void
290+
{
291+
$this->expectExecuteOutputAnswer(
292+
__DIR__ . '/input/21 - complex.txt',
293+
"STABLE" . PHP_EOL
294+
);
295+
}
296+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
.../\...
3+
../\/\..
4+
./\/\/\.
5+
/\/\/\/\
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
./\.
3+
/\/\
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
./\.
3+
/./\
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
...../\.....
3+
..../\/\....
4+
.../\/\/\...
5+
../\/\/\/\..
6+
./\/\/\/\/\.
7+
/\/\/\/\/\/\
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
..../\....
3+
.../\/\...
4+
../\/./\..
5+
./\.\/\/\.
6+
/\/\/\/\/\
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
........
3+
../\/\..
4+
./\/\/\.
5+
/\/\/\/\
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
........
3+
../\....
4+
./\/\...
5+
/\/\/\/\

0 commit comments

Comments
 (0)