Skip to content

Commit 3787061

Browse files
committed
Adding tests for "Network cabling".
1 parent 5646590 commit 3787061

File tree

12 files changed

+200208
-0
lines changed

12 files changed

+200208
-0
lines changed

CHANGELOG.md

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

1213
## [2.2.0] - 2022-02-10
1314
### Added
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Training\Medium\NetworkCabling;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Network cabling" puzzle.
11+
*/
12+
class NetworkCabling implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $N);
17+
for ($i = 0; $i < $N; $i++)
18+
{
19+
fscanf($stdin, "%d %d", $X, $Y);
20+
}
21+
22+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
23+
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
24+
25+
echo("answer\n");
26+
}
27+
}
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\NetworkCabling;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Training\Medium\NetworkCabling\NetworkCabling;
9+
10+
/**
11+
* Tests for the "Network cabling" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Training\Medium\NetworkCabling\NetworkCabling
14+
* @group networkCabling
15+
*/
16+
final class NetworkCablingTest extends PuzzleTest
17+
{
18+
public function setUp(): void
19+
{
20+
$this->puzzle = new NetworkCabling();
21+
}
22+
23+
/**
24+
* Test that the code can be executed for "Example 1".
25+
*
26+
* @group networkCabling_example1
27+
*/
28+
public function testCanExecuteExample1(): void
29+
{
30+
$this->expectExecuteOutputAnswer(
31+
__DIR__ . '/input/01 - example 1.txt',
32+
'4' . PHP_EOL
33+
);
34+
}
35+
36+
/**
37+
* Test that the code can be executed for "Example 2".
38+
*
39+
* @group networkCabling_example2
40+
*/
41+
public function testCanExecuteExample2(): void
42+
{
43+
$this->expectExecuteOutputAnswer(
44+
__DIR__ . '/input/02 - example 2.txt',
45+
'4' . PHP_EOL
46+
);
47+
}
48+
49+
/**
50+
* Test that the code can be executed for "Example 3".
51+
*
52+
* @group networkCabling_example3
53+
*/
54+
public function testCanExecuteExample3(): void
55+
{
56+
$this->expectExecuteOutputAnswer(
57+
__DIR__ . '/input/03 - example 3.txt',
58+
'5' . PHP_EOL
59+
);
60+
}
61+
62+
/**
63+
* Test that the code can be executed for "Example 4".
64+
*
65+
* @group networkCabling_example4
66+
*/
67+
public function testCanExecuteExample4(): void
68+
{
69+
$this->expectExecuteOutputAnswer(
70+
__DIR__ . '/input/04 - example 4.txt',
71+
'0' . PHP_EOL
72+
);
73+
}
74+
75+
/**
76+
* Test that the code can be executed for "Example 5".
77+
*
78+
* @group networkCabling_example5
79+
*/
80+
public function testCanExecuteExample5(): void
81+
{
82+
$this->expectExecuteOutputAnswer(
83+
__DIR__ . '/input/05 - example 5.txt',
84+
'18' . PHP_EOL
85+
);
86+
}
87+
88+
/**
89+
* Test that the code can be executed for "Example 6".
90+
*
91+
* @group networkCabling_example6
92+
*/
93+
public function testCanExecuteExample6(): void
94+
{
95+
$this->expectExecuteOutputAnswer(
96+
__DIR__ . '/input/06 - example 6.txt',
97+
'6066790161' . PHP_EOL
98+
);
99+
}
100+
101+
/**
102+
* Test that the code can be executed for "Example 7".
103+
*
104+
* @group networkCabling_example7
105+
*/
106+
public function testCanExecuteExample7(): void
107+
{
108+
$this->expectExecuteOutputAnswer(
109+
__DIR__ . '/input/07 - example 7.txt',
110+
'3142894' . PHP_EOL
111+
);
112+
}
113+
114+
/**
115+
* Test that the code can be executed for "Example 8".
116+
*
117+
* @group networkCabling_example8
118+
*/
119+
public function testCanExecuteExample8(): void
120+
{
121+
$this->expectExecuteOutputAnswer(
122+
__DIR__ . '/input/08 - example 8.txt',
123+
'2500049998' . PHP_EOL
124+
);
125+
}
126+
127+
/**
128+
* Test that the code can be executed for "Example 9".
129+
*
130+
* @group networkCabling_example9
131+
*/
132+
public function testCanExecuteExample9(): void
133+
{
134+
$this->expectExecuteOutputAnswer(
135+
__DIR__ . '/input/09 - example 9.txt',
136+
'2178614523' . PHP_EOL
137+
);
138+
}
139+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
0 0
3+
1 1
4+
2 2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1 2
3+
0 0
4+
2 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 2
3+
0 0
4+
2 2
5+
1 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
1 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
-5 -3
3+
-9 2
4+
3 -4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8
2+
-28189131 593661218
3+
102460950 1038903636
4+
938059973 -816049599
5+
-334087877 -290840615
6+
842560881 -116496866
7+
-416604701 690825290
8+
19715507 470868309
9+
846505116 -694479954

0 commit comments

Comments
 (0)