Skip to content

Commit 5a12cf6

Browse files
committed
Adding tests for "River crossing".
1 parent 0d9d3b2 commit 5a12cf6

14 files changed

+166
-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 "Fair numbering".
3737
- Tests for "A coin guessing game".
3838
- Tests for "Folding a note".
39+
- Tests for "River crossing".
3940

4041
## [3.11.0] - 2022-07-31
4142
### Added
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\RiverCrossing;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "River crossing" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/river-crossing
12+
*/
13+
class RiverCrossing implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
$INITIAL = stream_get_line($stdin, 10 + 1, "\n");
18+
$TARGET = stream_get_line($stdin, 10 + 1, "\n");
19+
20+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
21+
22+
echo("L L L L\n");
23+
echo("R L R L\n");
24+
}
25+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\RiverCrossing;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\RiverCrossing\RiverCrossing;
9+
10+
/**
11+
* Tests for the "River crossing" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\RiverCrossing\RiverCrossing
14+
* @group riverCrossing
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new RiverCrossing();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "The question is the solution".
26+
*
27+
* @group riverCrossing_theQuestionIsTheSolution
28+
*/
29+
public function testCanExecuteTheQuestionIsTheSolution(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - the question is the solution.txt',
33+
file_get_contents(__DIR__ . '/output/01 - the question is the solution.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "The start is the solution".
39+
*
40+
* @group riverCrossing_theStartIsTheSolution
41+
*/
42+
public function testCanExecuteTheStartIsTheSolution(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - the start is the solution.txt',
46+
"L L L R" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "From one side to the other".
52+
*
53+
* @group riverCrossing_fromOneSideToTheOther
54+
*/
55+
public function testCanExecuteFromOneSideToTheOther(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - from one side to the other.txt',
59+
file_get_contents(__DIR__ . '/output/03 - from one side to the other.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Mix it up".
65+
*
66+
* @group riverCrossing_mixItUp
67+
*/
68+
public function testCanExecuteMixItUp(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - mix it up.txt',
72+
file_get_contents(__DIR__ . '/output/04 - mix it up.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Rescue one".
78+
*
79+
* @group riverCrossing_rescueOne
80+
*/
81+
public function testCanExecuteRescueOne(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - rescue one.txt',
85+
file_get_contents(__DIR__ . '/output/05 - rescue one.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Sorted".
91+
*
92+
* @group riverCrossing_sorted
93+
*/
94+
public function testCanExecuteSorted(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - sorted.txt',
98+
file_get_contents(__DIR__ . '/output/06 - sorted.txt')
99+
);
100+
}
101+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R L R L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L R
2+
L L L R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R R R R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
R L R L
2+
L R L R
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L R
2+
L L L L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
R R R R
2+
L L R L
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
L L L L
2+
R L R L

0 commit comments

Comments
 (0)