Skip to content

Commit a396b19

Browse files
committed
Adding tests for "The electrician
apprentice".
1 parent b96b563 commit a396b19

File tree

15 files changed

+292
-0
lines changed

15 files changed

+292
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Tests for "A child's play".
1818
- Tests for "Sum of spiral's diagonals".
1919
- Tests for "Brackets, extreme edition".
20+
- Tests for "The electrician apprentice".
2021

2122
## [3.6.0] - 2022-03-11
2223
### Added
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\TheElectricianApprentice;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "The electrician apprentice" puzzle.
11+
*/
12+
class TheElectricianApprentice implements Puzzle
13+
{
14+
public function execute($stdin): void
15+
{
16+
fscanf($stdin, "%d", $C);
17+
for ($i = 0; $i < $C; $i++)
18+
{
19+
$WIRING = stream_get_line($stdin, 1024 + 1, "\n");
20+
}
21+
fscanf($stdin, "%d", $A);
22+
for ($i = 0; $i < $A; $i++)
23+
{
24+
$SWITCH = stream_get_line($stdin, 20 + 1, "\n");
25+
}
26+
for ($i = 0; $i < $C; $i++)
27+
{
28+
29+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
30+
31+
echo("ANSWER\n");
32+
}
33+
}
34+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Easy\TheElectricianApprentice;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\TheElectricianApprentice\TheElectricianApprentice;
9+
10+
/**
11+
* Tests for the "The electrician apprentice" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\TheElectricianApprentice\TheElectricianApprentice
14+
* @group theElectricianApprentice
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new TheElectricianApprentice();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "1 switch 1 light".
26+
*
27+
* @group theElectricianApprentice_1Switch1Light
28+
*/
29+
public function testCanExecuteOddSpiral(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - 1 switch 1 light.txt',
33+
"LIGHT is ON" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "2 parallel switches 1 light".
39+
*
40+
* @group theElectricianApprentice_2ParallelSwitches1Light
41+
*/
42+
public function testCanExecute2ParallelSwitches1Light(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - 2 parallel switches 1 light.txt',
46+
"LIGHT is ON" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "2 series switches 1 light".
52+
*
53+
* @group theElectricianApprentice_2SeriesSwitches1Light
54+
*/
55+
public function testCanExecute2SeriesSwitches1Light(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - 2 series switches 1 light.txt',
59+
"LIGHT is OFF" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Two lights".
65+
*
66+
* @group theElectricianApprentice_twoLights
67+
*/
68+
public function testCanExecuteTwoLights(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - two lights.txt',
72+
file_get_contents(__DIR__ . '/output/04 - two lights.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Series and parallel".
78+
*
79+
* @group theElectricianApprentice_seriesAndParallel
80+
*/
81+
public function testCanExecuteSeriesAndParallel(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - series and parallel.txt',
85+
"LIGHT is ON" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Mixed".
91+
*
92+
* @group theElectricianApprentice_mixed
93+
*/
94+
public function testCanExecuteMixed(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - mixed.txt',
98+
file_get_contents(__DIR__ . '/output/06 - mixed.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Weird Home".
104+
*
105+
* @group theElectricianApprentice_weirdHome
106+
*/
107+
public function testCanExecuteWeirdHome(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - weird home.txt',
111+
file_get_contents(__DIR__ . '/output/07 - weird home.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Regular Home".
117+
*
118+
* @group theElectricianApprentice_regularHome
119+
*/
120+
public function testCanExecuteRegulardHome(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - regular home.txt',
124+
file_get_contents(__DIR__ . '/output/08 - regular home.txt')
125+
);
126+
}
127+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
LIGHT - A1
3+
1
4+
A1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
LIGHT = A1 A2
3+
1
4+
A2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1
2+
LIGHT - A1 A2
3+
3
4+
A1
5+
A2
6+
A1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2
2+
LIGHT1 - A1
3+
LIGHT2 - B1
4+
2
5+
A1
6+
B1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1
2+
LIGHT - A1 = A2 A3
3+
6
4+
A1
5+
A1
6+
A2
7+
A2
8+
A3
9+
A1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2
2+
LIGHT1 - A1 = A2 A3
3+
LIGHT2 - B1 = B2 B3 = B4 B5
4+
6
5+
A1
6+
B1
7+
B2
8+
A3
9+
B5
10+
B4
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
6
2+
TV = A1 A2 - A3
3+
BOX = A1 A2 = A3 A4
4+
CONSOLE = A1 A2
5+
LIGHTS = B1 B2
6+
OVEN - KITCHEN = C1 C2 C3 - C4
7+
DISHWASHER - KITCHEN D1 D2 = D3 D4
8+
19
9+
A1
10+
B1
11+
A3
12+
C2
13+
C4
14+
A4
15+
A4
16+
A4
17+
A4
18+
D1
19+
KITCHEN
20+
D2
21+
A4
22+
A2
23+
KITCHEN
24+
D4
25+
A3
26+
C4
27+
KITCHEN

0 commit comments

Comments
 (0)