forked from exercism/php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOfLifeTest.php
More file actions
200 lines (173 loc) · 4.67 KB
/
Copy pathGameOfLifeTest.php
File metadata and controls
200 lines (173 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
class GameOfLifeTest extends TestCase
{
public static function setUpBeforeClass(): void
{
require_once 'GameOfLife.php';
}
/**
* uuid ae86ea7d-bd07-4357-90b3-ac7d256bd5c5
*/
#[TestDox('empty matrix')]
public function testEmptyMatrix(): void
{
$matrix = [];
$expected = [];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid 4ea5ccb7-7b73-4281-954a-bed1b0f139a5
*/
#[TestDox('live cells with zero live neighbors die')]
public function testLiveCellsWithZeroLiveNeighborsDie(): void
{
$matrix = [
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
];
$expected = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid df245adc-14ff-4f9c-b2ae-f465ef5321b2
*/
#[TestDox('live cells with only one live neighbor die')]
public function testLiveCellsWithOnlyOneLiveNeighborDie(): void
{
$matrix = [
[0, 0, 0],
[0, 1, 0],
[0, 1, 0]
];
$expected = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid 2a713b56-283c-48c8-adae-1d21306c80ae
*/
#[TestDox('live cells with two live neighbors stay alive')]
public function testLiveCellsWithTwoLiveNeighborsStayAlive(): void
{
$matrix = [
[1, 0, 1],
[1, 0, 1],
[1, 0, 1]
];
$expected = [
[0, 0, 0],
[1, 0, 1],
[0, 0, 0]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid 86d5c5a5-ab7b-41a1-8907-c9b3fc5e9dae
*/
#[TestDox('live cells with three live neighbors stay alive')]
public function testLiveCellsWithThreeLiveNeighborsStayAlive(): void
{
$matrix = [
[0, 1, 0],
[1, 0, 0],
[1, 1, 0]
];
$expected = [
[0, 0, 0],
[1, 0, 0],
[1, 1, 0]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid 015f60ac-39d8-4c6c-8328-57f334fc9f89
*/
#[TestDox('dead cells with three live neighbors become alive')]
public function testDeadCellsWithThreeLiveNeighborsBecomeAlive(): void
{
$matrix = [
[1, 1, 0],
[0, 0, 0],
[1, 0, 0]
];
$expected = [
[0, 0, 0],
[1, 1, 0],
[0, 0, 0]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid 2ee69c00-9d41-4b8b-89da-5832e735ccf1
*/
#[TestDox('live cells with four or more neighbors die')]
public function testLiveCellsWithFourOrMoreNeighborsDie(): void
{
$matrix = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
];
$expected = [
[1, 0, 1],
[0, 0, 0],
[1, 0, 1]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
/**
* uuid a79b42be-ed6c-4e27-9206-43da08697ef6
*/
#[TestDox('bigger matrix')]
public function testBiggerMatrix(): void
{
$matrix = [
[1, 1, 0, 1, 1, 0, 0, 0],
[1, 0, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 1, 1, 0],
[1, 0, 0, 0, 1, 1, 0, 0],
[1, 1, 0, 0, 0, 1, 1, 1],
[0, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 1]
];
$expected = [
[1, 1, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0],
[1, 0, 1, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 0, 0, 1, 0, 0, 1],
[1, 1, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1]
];
$subject = new GameOfLife($matrix);
$subject->tick();
$this->assertEquals($expected, $subject->matrix);
}
}