Skip to content

Commit 7ddcccd

Browse files
committed
Adding tests for "Game of life".
1 parent 5106819 commit 7ddcccd

File tree

16 files changed

+434
-0
lines changed

16 files changed

+434
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Tests for "Byte pair encoding".
3030
- Tests for "Find the missing plus signs in addition".
3131
- Tests for "Magic stones".
32+
- Tests for "Game of life".
3233

3334
## [3.13.0] - 2022-09-30
3435
### 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\Medium\GameOfLife;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Game of life" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/game-of-life
12+
*/
13+
class GameOfLife implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d", $width, $height);
18+
for ($i = 0; $i < $height; $i++)
19+
{
20+
fscanf($stdin, "%s", $line);
21+
}
22+
23+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
24+
25+
echo("answer\n");
26+
}
27+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\GameOfLife;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\GameOfLife\GameOfLife;
9+
10+
/**
11+
* Tests for the "Game of life" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\GameOfLife\GameOfLife
14+
* @group gameOfLife
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new GameOfLife();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "3x3".
26+
*
27+
* @group gameOfLife_3x3
28+
*/
29+
public function testCanExecute3x3(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - 3x3.txt',
33+
file_get_contents(__DIR__ . '/output/01 - 3x3.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "3x3".
39+
*
40+
* @group gameOfLife_3x3_2
41+
*/
42+
public function testCanExecute3x3_2(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - 3x3.txt',
46+
file_get_contents(__DIR__ . '/output/02 - 3x3.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "26x5".
52+
*
53+
* @group gameOfLife_26x5
54+
*/
55+
public function testCanExecute26x5(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - 26x5.txt',
59+
file_get_contents(__DIR__ . '/output/03 - 26x5.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "1x100".
65+
*
66+
* @group gameOfLife_1x100
67+
*/
68+
public function testCanExecute1x100(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - 1x100.txt',
72+
file_get_contents(__DIR__ . '/output/04 - 1x100.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "100x1".
78+
*
79+
* @group gameOfLife_100x1
80+
*/
81+
public function testCanExecute100x1(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 100x1.txt',
85+
file_get_contents(__DIR__ . '/output/05 - 100x1.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "30x30".
91+
*
92+
* @group gameOfLife_30x30
93+
*/
94+
public function testCanExecute30x30(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - 30x30.txt',
98+
file_get_contents(__DIR__ . '/output/06 - 30x30.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "1x1".
104+
*
105+
* @group gameOfLife_1x1
106+
*/
107+
public function testCanExecute1x1(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - 1x1.txt',
111+
0 . PHP_EOL
112+
);
113+
}
114+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 3
2+
000
3+
111
4+
000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 3
2+
010
3+
111
4+
010
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
26 5
2+
10110100001011110111100001
3+
10110101111011110111101101
4+
10000100001011110111101101
5+
10110101111011110111101101
6+
10110100001000010000100001
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
1 100
2+
0
3+
1
4+
0
5+
0
6+
0
7+
1
8+
0
9+
1
10+
0
11+
1
12+
0
13+
0
14+
1
15+
0
16+
1
17+
0
18+
0
19+
0
20+
0
21+
1
22+
0
23+
0
24+
0
25+
0
26+
0
27+
1
28+
0
29+
0
30+
0
31+
1
32+
1
33+
1
34+
1
35+
0
36+
0
37+
1
38+
1
39+
1
40+
0
41+
1
42+
1
43+
1
44+
0
45+
0
46+
1
47+
0
48+
1
49+
1
50+
0
51+
0
52+
0
53+
0
54+
1
55+
0
56+
0
57+
1
58+
1
59+
0
60+
0
61+
1
62+
0
63+
1
64+
0
65+
0
66+
0
67+
0
68+
0
69+
0
70+
0
71+
0
72+
0
73+
0
74+
0
75+
0
76+
1
77+
1
78+
0
79+
0
80+
0
81+
1
82+
0
83+
0
84+
0
85+
0
86+
1
87+
0
88+
0
89+
0
90+
1
91+
0
92+
0
93+
0
94+
0
95+
1
96+
0
97+
0
98+
1
99+
1
100+
1
101+
0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
100 1
2+
0010000101110011000010010000011000010100000001001001000010001010000010101000000110001000011011001000
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
30 30
2+
010100100001101010001000000000
3+
110000000111111100011100001110
4+
111010011101000000010010101100
5+
101001001000000010010100010100
6+
110000000000000110000010000001
7+
100100101010000010011001000000
8+
000110010001000010101001000011
9+
101001010010001000101101100100
10+
100010101011110110000100000100
11+
000001000001101101100111101100
12+
001001110100111111000000000011
13+
100000010010100000000010000000
14+
000001001000000110010011001010
15+
101100111011101000100000010010
16+
010000110110110101100010000010
17+
000000000000001100011110000000
18+
000110011110001100001110001000
19+
000000111000000100100000000001
20+
101010000100000000111001001100
21+
011100000000000011100100000001
22+
010110000001011000010000100001
23+
001001110100100000000100000100
24+
001001110000101100000000010100
25+
100000010100100100000000101000
26+
001010100100100001101100011000
27+
000000110101110001001000011011
28+
000001110000001000001000101000
29+
001000000010000000001001100101
30+
000101000101001000100000101001
31+
100100001000000110011001000000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 1
2+
0

0 commit comments

Comments
 (0)