Skip to content

Commit 671f1eb

Browse files
committed
Adding tests for "Equivalent resistance, circuit building".
1 parent cc69a57 commit 671f1eb

File tree

9 files changed

+159
-0
lines changed

9 files changed

+159
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Tests for "Walk on a die".
1010
- Tests for "Dolbear's law".
1111
- Tests for "ISBN check digit".
12+
- Tests for "Equivalent resistance, circuit building".
1213

1314
## [3.5.0] - 2022-02-22
1415
### 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\Community\Training\Easy\EquivalentResistanceCircuitBuilding;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Equivalent resistance, circuit building" puzzle.
11+
*/
12+
class EquivalentResistanceCircuitBuilding 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, "%s %d", $name, $R);
20+
}
21+
$circuit = stream_get_line(STDIN, 120 + 1, "\n");
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("Equivalent Resistance\n");
26+
}
27+
}
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\Easy\EquivalentResistanceCircuitBuilding;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\EquivalentResistanceCircuitBuilding\EquivalentResistanceCircuitBuilding;
9+
10+
/**
11+
* Tests for the "Equivalent resistance, circuit building" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\EquivalentResistanceCircuitBuilding\EquivalentResistanceCircuitBuilding
14+
* @group equivalentResistanceCircuitBuilding
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new EquivalentResistanceCircuitBuilding();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Series".
26+
*
27+
* @group equivalentResistanceCircuitBuilding_series
28+
*/
29+
public function testCanExecuteSeries(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - series.txt',
33+
30.0 . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Parallel".
39+
*
40+
* @group equivalentResistanceCircuitBuilding_parallel
41+
*/
42+
public function testCanExecuteParallel(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - parallel.txt',
46+
11.1 . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Combined (example diagram)".
52+
*
53+
* @group equivalentResistanceCircuitBuilding_combined
54+
*/
55+
public function testCanExecuteCombined(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - combined (example diagram).txt',
59+
10.7 . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Complex".
65+
*
66+
* @group equivalentResistanceCircuitBuilding_complex
67+
*/
68+
public function testCanExecuteComplex(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - complex.txt',
72+
2.4 . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "More complex".
78+
*
79+
* @group equivalentResistanceCircuitBuilding_moreComplex
80+
*/
81+
public function testCanExecuteMoreComplex(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - more complex.txt',
85+
45.0 . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "5-pointed star".
91+
*
92+
* @group equivalentResistanceCircuitBuilding_5PointedStar
93+
*/
94+
public function testCanExecute5PointedStar(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - 5-pointed star.txt',
98+
91.0 . PHP_EOL
99+
);
100+
}
101+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
A 20
3+
B 10
4+
( A B )
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
C 20
3+
D 25
4+
[ C D ]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
A 24
3+
B 8
4+
C 48
5+
[ ( A B ) [ C A ] ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
7
2+
Alfa 1
3+
Bravo 1
4+
Charlie 12
5+
Delta 4
6+
Echo 2
7+
Foxtrot 10
8+
Golf 8
9+
( Alfa [ Charlie Delta ( Bravo [ Echo ( Foxtrot Golf ) ] ) ] )
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
Alef 30
3+
Bet 20
4+
Vet 10
5+
( Alef [ ( Bet Bet Bet ) ( Vet [ ( Vet Vet ) ( Vet [ Bet Bet ] ) ] ) ] )
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
Star 78
3+
[ ( [ Star ( Star Star ) ] [ Star ( Star Star ) ] Star ) ( [ Star ( Star Star ) ] [ Star ( Star Star ) ] Star ) ]

0 commit comments

Comments
 (0)