Skip to content

Commit 31c4d1d

Browse files
committed
Adding tests for "Mountain map".
1 parent 021dd81 commit 31c4d1d

File tree

11 files changed

+131
-0
lines changed

11 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Tests for "Brackets, extreme edition".
2020
- Tests for "The electrician apprentice".
2121
- Tests for "Sudoku validator".
22+
- Tests for "Mountain map".
2223

2324
## [3.6.0] - 2022-03-11
2425
### Added
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\MountainMap;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Mountain map" puzzle.
11+
*/
12+
class MountainMap implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
// $n: the number of mountains
17+
fscanf($stdin, "%d", $n);
18+
$inputs = explode(" ", fgets($stdin));
19+
for ($i = 0; $i < $n; $i++)
20+
{
21+
$height = intval($inputs[$i]); // height of the mountain
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("answer\n");
27+
}
28+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\MountainMap;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\MountainMap\MountainMap;
9+
10+
/**
11+
* Tests for the "Mountain map" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\MountainMap\MountainMap
14+
* @group mountainMap
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new MountainMap();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Test 1".
26+
*
27+
* @group mountainMap_test1
28+
*/
29+
public function testCanExecuteTest1(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - test 1.txt',
33+
file_get_contents(__DIR__ . '/output/01 - test 1.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Test 2".
39+
*
40+
* @group MountainMap_test2
41+
*/
42+
public function testCanExecuteTest2(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - test 2.txt',
46+
file_get_contents(__DIR__ . '/output/02 - test 2.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Test 3".
52+
*
53+
* @group MountainMap_test3
54+
*/
55+
public function testCanExecuteTest3(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - test 3.txt',
59+
file_get_contents(__DIR__ . '/output/03 - test 3.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Test 4".
65+
*
66+
* @group MountainMap_test4
67+
*/
68+
public function testCanExecuteTest4(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - test 4.txt',
72+
file_get_contents(__DIR__ . '/output/04 - test 4.txt')
73+
);
74+
}
75+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
1 2 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
4
2+
3 7 2 9
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
7
2+
7 2 3 4 1 2 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/\
2+
/\/ \/\
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/\
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/\
2+
/ \
3+
/\ / \
4+
/ \ / \
5+
/ \ / \
6+
/ \ / \
7+
/\ / \ / \
8+
/ \ / \ /\ / \
9+
/ \/ \/ \/ \

0 commit comments

Comments
 (0)