Skip to content

Commit ecbc7f9

Browse files
committed
Adding tests for "Elementary cellular
automaton".
1 parent 814a750 commit ecbc7f9

File tree

13 files changed

+201
-0
lines changed

13 files changed

+201
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Tests for "Derivative time !!! - part1".
2424
- Tests for "Merlin's magic square".
2525
- Tests for "Windmill problem".
26+
- Tests for "Elementary cellular automaton".
2627

2728
## [3.12.0] - 2022-09-01
2829
### Added
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\ElementaryCellularAutomaton;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Elementary cellular automaton" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/elementary-cellular-automaton
12+
*/
13+
class ElementaryCellularAutomaton implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $R);
18+
fscanf($stdin, "%d", $N);
19+
fscanf($stdin, "%s", $startPattern);
20+
21+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
22+
23+
echo(".....@.@.....\n");
24+
}
25+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\ElementaryCellularAutomaton;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\ElementaryCellularAutomaton\ElementaryCellularAutomaton;
9+
10+
/**
11+
* Tests for the "Elementary cellular automaton" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\ElementaryCellularAutomaton\ElementaryCellularAutomaton
14+
* @group elementaryCellularAutomaton
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new ElementaryCellularAutomaton();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Pyramid".
26+
*
27+
* @group elementaryCellularAutomaton_pyramid
28+
*/
29+
public function testCanExecutePyramid(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - pyramid.txt',
33+
file_get_contents(__DIR__ . '/output/01 - pyramid.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Sierpiński triangle".
39+
*
40+
* @group elementaryCellularAutomaton_sierpinskiTriangle
41+
*/
42+
public function testCanExecuteSierpinskiTriangle(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - sierpiński triangle.txt',
46+
file_get_contents(__DIR__ . '/output/02 - sierpiński triangle.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Rule 30: conus textile".
52+
*
53+
* @group elementaryCellularAutomaton_rule30ConusTextile
54+
*/
55+
public function testCanExecuteRule30ConusTextile(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - rule 30: conus textile.txt',
59+
file_get_contents(__DIR__ . '/output/03 - rule 30: conus textile.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Sierpiński triangle, continued".
65+
*
66+
* @group elementaryCellularAutomaton_sierpinskiTriangleContinued
67+
*/
68+
public function testCanExecuteSierpinskiTriangleContinued(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - sierpiński triangle, continued.txt',
72+
file_get_contents(__DIR__ . '/output/04 - sierpiński triangle, continued.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Rule 110, different start".
78+
*
79+
* @group elementaryCellularAutomaton_rule110DifferentStart
80+
*/
81+
public function testCanExecuteRule110DifferentStart(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - rule 110, different start.txt',
85+
file_get_contents(__DIR__ . '/output/05 - rule 110, different start.txt')
86+
);
87+
}
88+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
254
2+
5
3+
.....@.....
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
90
2+
16
3+
...............@...............
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
30
2+
14
3+
..............@..............
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
90
2+
16
3+
........@........
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
110
2+
21
3+
....@..@@@.@@..........
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.....@.....
2+
....@@@....
3+
...@@@@@...
4+
..@@@@@@@..
5+
.@@@@@@@@@.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
...............@...............
2+
..............@.@..............
3+
.............@...@.............
4+
............@.@.@.@............
5+
...........@.......@...........
6+
..........@.@.....@.@..........
7+
.........@...@...@...@.........
8+
........@.@.@.@.@.@.@.@........
9+
.......@...............@.......
10+
......@.@.............@.@......
11+
.....@...@...........@...@.....
12+
....@.@.@.@.........@.@.@.@....
13+
...@.......@.......@.......@...
14+
..@.@.....@.@.....@.@.....@.@..
15+
.@...@...@...@...@...@...@...@.
16+
@.@.@.@.@.@.@.@.@.@.@.@.@.@.@.@

0 commit comments

Comments
 (0)