Skip to content

Commit cd8a199

Browse files
committed
Adding tests for "War".
1 parent c6b371b commit cd8a199

File tree

12 files changed

+542
-0
lines changed

12 files changed

+542
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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]
8+
### Added
9+
- Tests for "War".
10+
711
## [2.2.0] - 2022-02-10
812
### Added
913
- Tests for "Conway sequence".

src/Training/Medium/War/War.dist

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Medium\War;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "War" puzzle.
11+
*/
12+
class War implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
// $n: the number of cards for player 1
17+
fscanf($stdin, "%d", $n);
18+
for ($i = 0; $i < $n; $i++)
19+
{
20+
// $cardp1: the n cards of player 1
21+
fscanf($stdin, "%s", $cardp1);
22+
}
23+
// $m: the number of cards for player 2
24+
fscanf($stdin, "%d", $m);
25+
for ($i = 0; $i < $m; $i++)
26+
{
27+
// $cardp2: the m cards of player 2
28+
fscanf($stdin, "%s", $cardp2);
29+
}
30+
31+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
32+
33+
echo("PAT\n");
34+
}
35+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Medium\War;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\War\War;
9+
10+
/**
11+
* Tests for the "War" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\War\War
14+
* @group war
15+
*/
16+
final class WarTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new War();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "3 cards".
25+
*
26+
* @group war_3cards
27+
*/
28+
public function testCanExecute3Cards(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - 3 cards.txt',
32+
'1 3' . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "26 cards".
38+
*
39+
* @group war_26cards
40+
*/
41+
public function testCanExecute26Cards(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - 26 cards.txt',
45+
'2 26' . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "26 cards, medium length".
51+
*
52+
* @group war_26cardsMediumLength
53+
*/
54+
public function testCanExecute26CardsMediumLength(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - 26 cards medium length.txt',
58+
'2 56' . PHP_EOL
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Battle".
64+
*
65+
* @group war_battle
66+
*/
67+
public function testCanExecuteBattle(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - battle.txt',
71+
'2 1' . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "One game, one battle".
77+
*
78+
* @group war_oneGameOneBattle
79+
*/
80+
public function testCanExecuteOneGameOneBattle(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - one game one battle.txt',
84+
'1 52' . PHP_EOL
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "2 chained battles".
90+
*
91+
* @group war_2ChainedBattles
92+
*/
93+
public function testCanExecute2ChainedBattles(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - 2 chained battles.txt',
97+
'2 1' . PHP_EOL
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Long game".
103+
*
104+
* @group war_longGame
105+
*/
106+
public function testCanExecuteLongGame(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - long game.txt',
110+
'2 1262' . PHP_EOL
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "PAT".
116+
*
117+
* @group war_PAT
118+
*/
119+
public function testCanExecutePAT(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - PAT.txt',
123+
'PAT' . PHP_EOL
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Another PAT".
129+
*
130+
* @group war_anotherPAT
131+
*/
132+
public function testCanExecuteAnotherPAT(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - another PAT.txt',
136+
'PAT' . PHP_EOL
137+
);
138+
}
139+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
AD
3+
KC
4+
QC
5+
3
6+
KH
7+
QS
8+
JC
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
5C
3+
3D
4+
2C
5+
7D
6+
8C
7+
7S
8+
5D
9+
5H
10+
6D
11+
5S
12+
4D
13+
6H
14+
6S
15+
3C
16+
3S
17+
7C
18+
4S
19+
4H
20+
7H
21+
4C
22+
2H
23+
6C
24+
8D
25+
3H
26+
2D
27+
2S
28+
26
29+
AC
30+
9H
31+
KH
32+
KC
33+
KD
34+
KS
35+
10S
36+
10D
37+
9S
38+
QD
39+
JS
40+
10H
41+
8S
42+
QH
43+
JD
44+
AD
45+
JC
46+
AS
47+
QS
48+
AH
49+
JH
50+
10C
51+
9C
52+
8H
53+
QC
54+
9D
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
6H
3+
7H
4+
6C
5+
QS
6+
7S
7+
8D
8+
6D
9+
5S
10+
6S
11+
QH
12+
4D
13+
3S
14+
7C
15+
3C
16+
4S
17+
5H
18+
QD
19+
5C
20+
3H
21+
3D
22+
8C
23+
4H
24+
4C
25+
QC
26+
5D
27+
7D
28+
26
29+
JH
30+
AH
31+
KD
32+
AD
33+
9C
34+
2D
35+
2H
36+
JC
37+
10C
38+
KC
39+
10D
40+
JS
41+
JD
42+
9D
43+
9S
44+
KS
45+
AS
46+
KH
47+
10S
48+
8S
49+
2S
50+
10H
51+
8H
52+
AC
53+
2C
54+
9H
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
5
2+
8C
3+
KD
4+
AH
5+
QH
6+
2S
7+
5
8+
8D
9+
2D
10+
3H
11+
4D
12+
3S
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
10H
3+
KD
4+
6C
5+
10S
6+
8S
7+
AD
8+
QS
9+
3D
10+
7H
11+
KH
12+
9D
13+
2D
14+
JC
15+
KS
16+
3S
17+
2S
18+
QC
19+
AC
20+
JH
21+
7D
22+
KC
23+
10D
24+
4C
25+
AS
26+
5D
27+
5S
28+
26
29+
2H
30+
9C
31+
8C
32+
4S
33+
5C
34+
AH
35+
JD
36+
QH
37+
7C
38+
5H
39+
4H
40+
6H
41+
6S
42+
QD
43+
9H
44+
10C
45+
4D
46+
JS
47+
6D
48+
3H
49+
8H
50+
3C
51+
7S
52+
9S
53+
8D
54+
2C
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
9
2+
8C
3+
KD
4+
AH
5+
QH
6+
3D
7+
KD
8+
AH
9+
QH
10+
6D
11+
9
12+
8D
13+
2D
14+
3H
15+
4D
16+
3S
17+
2D
18+
3H
19+
4D
20+
7H

0 commit comments

Comments
 (0)