Skip to content

Commit 62d741e

Browse files
committed
Adding tests for "Plight of the fellowship
of the ring".
1 parent b3e9775 commit 62d741e

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Tests for "Bit count to limit".
3333
- Tests for "Porcupine fever".
3434
- Tests for "Bijective numeration".
35+
- Tests for "Plight of the fellowship of the ring".
3536

3637
### Fixed
3738
- Tests groups for "CGFunge interpreter".
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\PlightOfTheFellowshipOfTheRing;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Plight of the fellowship of the ring" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/plight-of-the-fellowship-of-the-ring
12+
*/
13+
class PlightOfTheFellowshipOfTheRing implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $N);
18+
fscanf($stdin, "%d", $M);
19+
fscanf($stdin, "%d", $L);
20+
for ($i = 0; $i < $N; $i++)
21+
{
22+
fscanf($stdin, "%d %d", $XS, $YS);
23+
}
24+
for ($i = 0; $i < $M; $i++)
25+
{
26+
fscanf($stdin, "%d %d", $XO, $YO);
27+
}
28+
for ($i = 0; $i < $L; $i++)
29+
{
30+
fscanf($stdin, "%d %d", $N1, $N2);
31+
}
32+
fscanf($stdin, "%d", $S);
33+
fscanf($stdin, "%d", $E);
34+
35+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
36+
37+
echo("path\n");
38+
}
39+
}
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\Medium\PlightOfTheFellowshipOfTheRing;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\PlightOfTheFellowshipOfTheRing\PlightOfTheFellowshipOfTheRing;
9+
10+
/**
11+
* Tests for the "Plight of the fellowship of the ring" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\PlightOfTheFellowshipOfTheRing\PlightOfTheFellowshipOfTheRing
14+
* @group plightOfTheFellowshipOfTheRing
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new PlightOfTheFellowshipOfTheRing();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "One orc".
26+
*
27+
* @group plightOfTheFellowshipOfTheRing_oneOrc
28+
*/
29+
public function testCanExecuteOneOrc(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - one orc.txt',
33+
"0 1 3" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Multiple orcs".
39+
*
40+
* @group plightOfTheFellowshipOfTheRing_multipleOrcs
41+
*/
42+
public function testCanExecuteMultipleOrcs(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - multiple orcs.txt',
46+
"0 1 3 4 6" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Many choices".
52+
*
53+
* @group plightOfTheFellowshipOfTheRing_manyChoices
54+
*/
55+
public function testCanExecuteManyChoices(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - many choices.txt',
59+
"0 1 2 8 9 10 11 7" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Impossible".
65+
*
66+
* @group plightOfTheFellowshipOfTheRing_impossible
67+
*/
68+
public function testCanExecuteImpossible(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - impossible.txt',
72+
"IMPOSSIBLE" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "No orcs!".
78+
*
79+
* @group plightOfTheFellowshipOfTheRing_noOrcs
80+
*/
81+
public function testCanExecuteNoOrcs(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - no orcs!.txt',
85+
"0 2 3" . PHP_EOL
86+
);
87+
}
88+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
4
2+
1
3+
4
4+
1 1
5+
2 0
6+
2 2
7+
3 1
8+
1 2
9+
0 1
10+
0 2
11+
1 3
12+
2 3
13+
0
14+
3
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
9
2+
3
3+
9
4+
0 0
5+
3 0
6+
5 -2
7+
5 2
8+
8 2
9+
8 -2
10+
10 0
11+
10 4
12+
3 4
13+
8 -4
14+
1 4
15+
10 8
16+
0 1
17+
1 2
18+
1 3
19+
2 5
20+
3 4
21+
5 6
22+
4 7
23+
4 6
24+
3 8
25+
0
26+
6
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
12
2+
2
3+
13
4+
0 0
5+
3 0
6+
5 -2
7+
5 2
8+
8 2
9+
8 -2
10+
10 0
11+
-2 10
12+
5 -5
13+
-3 -5
14+
-3 0
15+
-3 5
16+
5 4
17+
12 5
18+
0 1
19+
1 2
20+
1 3
21+
2 5
22+
3 6
23+
5 6
24+
6 4
25+
4 7
26+
2 8
27+
8 9
28+
9 10
29+
10 11
30+
11 7
31+
0
32+
7
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
3
2+
1
3+
2
4+
0 0
5+
3 0
6+
5 2
7+
5 3
8+
0 1
9+
1 2
10+
0
11+
2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
4
2+
0
3+
4
4+
1 1
5+
2 2
6+
2 0
7+
3 1
8+
0 1
9+
0 2
10+
1 2
11+
2 3
12+
0
13+
3

0 commit comments

Comments
 (0)