Skip to content

Commit 5646590

Browse files
committed
Adding tests for "Dwarfs standing on the shoulders of giants".
1 parent 04dee1c commit 5646590

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Tests for "War".
10+
- Tests for "Dwarfs standing on the shoulders of giants".
1011

1112
## [2.2.0] - 2022-02-10
1213
### Added
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Medium\DwarfsStandingOnTheShouldersOfGiants;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Dwarfs standing on the shoulders of giants" puzzle.
11+
*/
12+
class DwarfsStandingOnTheShouldersOfGiants implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
// $n: the number of relationships of influence
17+
fscanf($stdin, "%d", $n);
18+
for ($i = 0; $i < $n; $i++)
19+
{
20+
// $x: a relationship of influence between two people (x influences y)
21+
fscanf($stdin, "%d %d", $x, $y);
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
27+
// The number of people involved in the longest succession of influences
28+
echo("2\n");
29+
}
30+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Training\Medium\DwarfsStandingOnTheShouldersOfGiants;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\DwarfsStandingOnTheShouldersOfGiants\DwarfsStandingOnTheShouldersOfGiants;
9+
10+
/**
11+
* Tests for the "Dwarfs standing on the shoulders of giants" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\DwarfsStandingOnTheShouldersOfGiants\DwarfsStandingOnTheShouldersOfGiants
14+
* @group dwarfsStandingOnTheShouldersOfGiants
15+
*/
16+
final class DwarfsStandingOnTheShouldersOfGiantsTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new DwarfsStandingOnTheShouldersOfGiants();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Simple example".
25+
*
26+
* @group dwarfsStandingOnTheShouldersOfGiants_simpleExample
27+
*/
28+
public function testCanExecuteSimpleExample(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - simple example.txt',
32+
'3' . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "Complete example".
38+
*
39+
* @group dwarfsStandingOnTheShouldersOfGiants_completeExample
40+
*/
41+
public function testCanExecuteCompleteExample(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - complete example.txt',
45+
'4' . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "Several mentors".
51+
*
52+
* @group dwarfsStandingOnTheShouldersOfGiants_severalMentors
53+
*/
54+
public function testCanExecuteSeveralMentors(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - several mentors.txt',
58+
'3' . PHP_EOL
59+
);
60+
}
61+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1 2
3+
1 3
4+
3 4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
1 2
3+
1 3
4+
3 4
5+
2 4
6+
2 5
7+
10 11
8+
10 1
9+
10 3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
2 3
3+
8 9
4+
1 2
5+
6 3

0 commit comments

Comments
 (0)