Skip to content

Commit 5b550ec

Browse files
committed
Fix test case formatting
1 parent d75f149 commit 5b550ec

2 files changed

Lines changed: 102 additions & 122 deletions

File tree

exercises/practice/game-of-life/.meta/template.j2

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
class {{ exercise | camel_case }}Test(unittest.TestCase):
77
{% for case in cases %}
88
def test_{{ case.description | to_snake }}(self):
9+
matrix = [
10+
{% for row in case.input.matrix %}
11+
{{ row }},
12+
{% endfor %}
13+
]
14+
expected = [
15+
{% for row in case.expected %}
16+
{{ row }},
17+
{% endfor %}
18+
]
919
self.assertEqual(
10-
tick(
11-
[
12-
{% for row in case.input.matrix %}
13-
{{ row }},
14-
{% endfor %}
15-
]
16-
),
17-
[
18-
{% for row in case.expected %}
19-
{{ row }},
20-
{% endfor %}
21-
]
20+
tick(matrix), expected
2221
)
2322
{% endfor %}
Lines changed: 91 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/game-of-life/canonical-data.json
3-
# File last updated on 2026-01-25
3+
# File last updated on 2026-01-26
44

55
import unittest
66

@@ -11,126 +11,107 @@
1111

1212
class GameOfLifeTest(unittest.TestCase):
1313
def test_empty_matrix(self):
14-
self.assertEqual(tick([]), [])
14+
matrix = []
15+
expected = []
16+
self.assertEqual(tick(matrix), expected)
1517

1618
def test_live_cells_with_zero_live_neighbors_die(self):
17-
self.assertEqual(
18-
tick(
19-
[
20-
[0, 0, 0],
21-
[0, 1, 0],
22-
[0, 0, 0],
23-
]
24-
),
25-
[
26-
[0, 0, 0],
27-
[0, 0, 0],
28-
[0, 0, 0],
29-
],
30-
)
19+
matrix = [
20+
[0, 0, 0],
21+
[0, 1, 0],
22+
[0, 0, 0],
23+
]
24+
expected = [
25+
[0, 0, 0],
26+
[0, 0, 0],
27+
[0, 0, 0],
28+
]
29+
self.assertEqual(tick(matrix), expected)
3130

3231
def test_live_cells_with_only_one_live_neighbor_die(self):
33-
self.assertEqual(
34-
tick(
35-
[
36-
[0, 0, 0],
37-
[0, 1, 0],
38-
[0, 1, 0],
39-
]
40-
),
41-
[
42-
[0, 0, 0],
43-
[0, 0, 0],
44-
[0, 0, 0],
45-
],
46-
)
32+
matrix = [
33+
[0, 0, 0],
34+
[0, 1, 0],
35+
[0, 1, 0],
36+
]
37+
expected = [
38+
[0, 0, 0],
39+
[0, 0, 0],
40+
[0, 0, 0],
41+
]
42+
self.assertEqual(tick(matrix), expected)
4743

4844
def test_live_cells_with_two_live_neighbors_stay_alive(self):
49-
self.assertEqual(
50-
tick(
51-
[
52-
[1, 0, 1],
53-
[1, 0, 1],
54-
[1, 0, 1],
55-
]
56-
),
57-
[
58-
[0, 0, 0],
59-
[1, 0, 1],
60-
[0, 0, 0],
61-
],
62-
)
45+
matrix = [
46+
[1, 0, 1],
47+
[1, 0, 1],
48+
[1, 0, 1],
49+
]
50+
expected = [
51+
[0, 0, 0],
52+
[1, 0, 1],
53+
[0, 0, 0],
54+
]
55+
self.assertEqual(tick(matrix), expected)
6356

6457
def test_live_cells_with_three_live_neighbors_stay_alive(self):
65-
self.assertEqual(
66-
tick(
67-
[
68-
[0, 1, 0],
69-
[1, 0, 0],
70-
[1, 1, 0],
71-
]
72-
),
73-
[
74-
[0, 0, 0],
75-
[1, 0, 0],
76-
[1, 1, 0],
77-
],
78-
)
58+
matrix = [
59+
[0, 1, 0],
60+
[1, 0, 0],
61+
[1, 1, 0],
62+
]
63+
expected = [
64+
[0, 0, 0],
65+
[1, 0, 0],
66+
[1, 1, 0],
67+
]
68+
self.assertEqual(tick(matrix), expected)
7969

8070
def test_dead_cells_with_three_live_neighbors_become_alive(self):
81-
self.assertEqual(
82-
tick(
83-
[
84-
[1, 1, 0],
85-
[0, 0, 0],
86-
[1, 0, 0],
87-
]
88-
),
89-
[
90-
[0, 0, 0],
91-
[1, 1, 0],
92-
[0, 0, 0],
93-
],
94-
)
71+
matrix = [
72+
[1, 1, 0],
73+
[0, 0, 0],
74+
[1, 0, 0],
75+
]
76+
expected = [
77+
[0, 0, 0],
78+
[1, 1, 0],
79+
[0, 0, 0],
80+
]
81+
self.assertEqual(tick(matrix), expected)
9582

9683
def test_live_cells_with_four_or_more_neighbors_die(self):
97-
self.assertEqual(
98-
tick(
99-
[
100-
[1, 1, 1],
101-
[1, 1, 1],
102-
[1, 1, 1],
103-
]
104-
),
105-
[
106-
[1, 0, 1],
107-
[0, 0, 0],
108-
[1, 0, 1],
109-
],
110-
)
84+
matrix = [
85+
[1, 1, 1],
86+
[1, 1, 1],
87+
[1, 1, 1],
88+
]
89+
expected = [
90+
[1, 0, 1],
91+
[0, 0, 0],
92+
[1, 0, 1],
93+
]
94+
self.assertEqual(tick(matrix), expected)
11195

11296
def test_bigger_matrix(self):
113-
self.assertEqual(
114-
tick(
115-
[
116-
[1, 1, 0, 1, 1, 0, 0, 0],
117-
[1, 0, 1, 1, 0, 0, 0, 0],
118-
[1, 1, 1, 0, 0, 1, 1, 1],
119-
[0, 0, 0, 0, 0, 1, 1, 0],
120-
[1, 0, 0, 0, 1, 1, 0, 0],
121-
[1, 1, 0, 0, 0, 1, 1, 1],
122-
[0, 0, 1, 0, 1, 0, 0, 1],
123-
[1, 0, 0, 0, 0, 0, 1, 1],
124-
]
125-
),
126-
[
127-
[1, 1, 0, 1, 1, 0, 0, 0],
128-
[0, 0, 0, 0, 0, 1, 1, 0],
129-
[1, 0, 1, 1, 1, 1, 0, 1],
130-
[1, 0, 0, 0, 0, 0, 0, 1],
131-
[1, 1, 0, 0, 1, 0, 0, 1],
132-
[1, 1, 0, 1, 0, 0, 0, 1],
133-
[1, 0, 0, 0, 0, 0, 0, 0],
134-
[0, 0, 0, 0, 0, 0, 1, 1],
135-
],
136-
)
97+
matrix = [
98+
[1, 1, 0, 1, 1, 0, 0, 0],
99+
[1, 0, 1, 1, 0, 0, 0, 0],
100+
[1, 1, 1, 0, 0, 1, 1, 1],
101+
[0, 0, 0, 0, 0, 1, 1, 0],
102+
[1, 0, 0, 0, 1, 1, 0, 0],
103+
[1, 1, 0, 0, 0, 1, 1, 1],
104+
[0, 0, 1, 0, 1, 0, 0, 1],
105+
[1, 0, 0, 0, 0, 0, 1, 1],
106+
]
107+
expected = [
108+
[1, 1, 0, 1, 1, 0, 0, 0],
109+
[0, 0, 0, 0, 0, 1, 1, 0],
110+
[1, 0, 1, 1, 1, 1, 0, 1],
111+
[1, 0, 0, 0, 0, 0, 0, 1],
112+
[1, 1, 0, 0, 1, 0, 0, 1],
113+
[1, 1, 0, 1, 0, 0, 0, 1],
114+
[1, 0, 0, 0, 0, 0, 0, 0],
115+
[0, 0, 0, 0, 0, 0, 1, 1],
116+
]
117+
self.assertEqual(tick(matrix), expected)

0 commit comments

Comments
 (0)