Skip to content

Commit 5a88a0f

Browse files
game-of-life: add generator
1 parent 3b743d7 commit 5a88a0f

File tree

2 files changed

+97
-68
lines changed

2 files changed

+97
-68
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Xunit;
2+
3+
public class {{ testClass }}
4+
{
5+
{{- for test in tests }}
6+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
7+
public void {{ test.testMethod }}()
8+
{
9+
int[,] matrix =
10+
{
11+
{{- for row in test.input.matrix }}
12+
{ {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}}
13+
{{ end }}
14+
};
15+
{{- if test.expected.empty? }}
16+
Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(matrix));
17+
{{ else }}
18+
int[,] expected =
19+
{
20+
{{- for row in test.expected }}
21+
{ {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}}
22+
{{ end }}
23+
};
24+
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(matrix));
25+
{{ end -}}
26+
}
27+
{{ end -}}
28+
}

exercises/practice/game-of-life/GameOfLifeTests.cs

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,148 @@
1-
using System;
21
using Xunit;
32

43
public class GameOfLifeTests
54
{
65
[Fact]
76
public void Empty_matrix()
87
{
9-
var matrix = new int[,] { };
8+
int[,] matrix =
9+
{
10+
};
1011
Assert.Empty(GameOfLife.Tick(matrix));
1112
}
1213

1314
[Fact(Skip = "Remove this Skip property to run this test")]
1415
public void Live_cells_with_zero_live_neighbors_die()
1516
{
16-
var matrix = new[,]
17+
int[,] matrix =
1718
{
18-
{ 0, 0, 0 },
19-
{ 0, 1, 0 },
20-
{ 0, 0, 0 }
19+
{ 0, 0, 0 },
20+
{ 0, 1, 0 },
21+
{ 0, 0, 0 }
2122
};
22-
var expected = new[,]
23+
int[,] expected =
2324
{
24-
{ 0, 0, 0 },
25-
{ 0, 0, 0 },
26-
{ 0, 0, 0 }
25+
{ 0, 0, 0 },
26+
{ 0, 0, 0 },
27+
{ 0, 0, 0 }
2728
};
2829
Assert.Equal(expected, GameOfLife.Tick(matrix));
2930
}
3031

3132
[Fact(Skip = "Remove this Skip property to run this test")]
3233
public void Live_cells_with_only_one_live_neighbor_die()
3334
{
34-
var matrix = new[,]
35+
int[,] matrix =
3536
{
36-
{ 0, 0, 0 },
37-
{ 0, 1, 0 },
38-
{ 0, 1, 0 }
37+
{ 0, 0, 0 },
38+
{ 0, 1, 0 },
39+
{ 0, 1, 0 }
3940
};
40-
var expected = new[,]
41+
int[,] expected =
4142
{
42-
{ 0, 0, 0 },
43-
{ 0, 0, 0 },
44-
{ 0, 0, 0 }
43+
{ 0, 0, 0 },
44+
{ 0, 0, 0 },
45+
{ 0, 0, 0 }
4546
};
4647
Assert.Equal(expected, GameOfLife.Tick(matrix));
4748
}
4849

4950
[Fact(Skip = "Remove this Skip property to run this test")]
5051
public void Live_cells_with_two_live_neighbors_stay_alive()
5152
{
52-
var matrix = new[,]
53+
int[,] matrix =
5354
{
54-
{ 1, 0, 1 },
55-
{ 1, 0, 1 },
56-
{ 1, 0, 1 }
55+
{ 1, 0, 1 },
56+
{ 1, 0, 1 },
57+
{ 1, 0, 1 }
5758
};
58-
var expected = new[,]
59+
int[,] expected =
5960
{
60-
{ 0, 0, 0 },
61-
{ 1, 0, 1 },
62-
{ 0, 0, 0 }
61+
{ 0, 0, 0 },
62+
{ 1, 0, 1 },
63+
{ 0, 0, 0 }
6364
};
6465
Assert.Equal(expected, GameOfLife.Tick(matrix));
6566
}
6667

6768
[Fact(Skip = "Remove this Skip property to run this test")]
6869
public void Live_cells_with_three_live_neighbors_stay_alive()
6970
{
70-
var matrix = new[,]
71+
int[,] matrix =
7172
{
72-
{ 0, 1, 0 },
73-
{ 1, 0, 0 },
74-
{ 1, 1, 0 }
73+
{ 0, 1, 0 },
74+
{ 1, 0, 0 },
75+
{ 1, 1, 0 }
7576
};
76-
var expected = new[,]
77+
int[,] expected =
7778
{
78-
{ 0, 0, 0 },
79-
{ 1, 0, 0 },
80-
{ 1, 1, 0 }
79+
{ 0, 0, 0 },
80+
{ 1, 0, 0 },
81+
{ 1, 1, 0 }
8182
};
8283
Assert.Equal(expected, GameOfLife.Tick(matrix));
8384
}
8485

8586
[Fact(Skip = "Remove this Skip property to run this test")]
8687
public void Dead_cells_with_three_live_neighbors_become_alive()
8788
{
88-
var matrix = new[,]
89+
int[,] matrix =
8990
{
90-
{ 1, 1, 0 },
91-
{ 0, 0, 0 },
92-
{ 1, 0, 0 }
91+
{ 1, 1, 0 },
92+
{ 0, 0, 0 },
93+
{ 1, 0, 0 }
9394
};
94-
var expected = new[,]
95+
int[,] expected =
9596
{
96-
{ 0, 0, 0 },
97-
{ 1, 1, 0 },
98-
{ 0, 0, 0 }
97+
{ 0, 0, 0 },
98+
{ 1, 1, 0 },
99+
{ 0, 0, 0 }
99100
};
100101
Assert.Equal(expected, GameOfLife.Tick(matrix));
101102
}
102103

103104
[Fact(Skip = "Remove this Skip property to run this test")]
104105
public void Live_cells_with_four_or_more_neighbors_die()
105106
{
106-
var matrix = new[,]
107+
int[,] matrix =
107108
{
108-
{ 1, 1, 1 },
109-
{ 1, 1, 1 },
110-
{ 1, 1, 1 }
109+
{ 1, 1, 1 },
110+
{ 1, 1, 1 },
111+
{ 1, 1, 1 }
111112
};
112-
var expected = new[,]
113+
int[,] expected =
113114
{
114-
{ 1, 0, 1 },
115-
{ 0, 0, 0 },
116-
{ 1, 0, 1 }
115+
{ 1, 0, 1 },
116+
{ 0, 0, 0 },
117+
{ 1, 0, 1 }
117118
};
118119
Assert.Equal(expected, GameOfLife.Tick(matrix));
119120
}
120121

121122
[Fact(Skip = "Remove this Skip property to run this test")]
122123
public void Bigger_matrix()
123124
{
124-
var matrix = new[,]
125+
int[,] matrix =
125126
{
126-
{ 1, 1, 0, 1, 1, 0, 0, 0 },
127-
{ 1, 0, 1, 1, 0, 0, 0, 0 },
128-
{ 1, 1, 1, 0, 0, 1, 1, 1 },
129-
{ 0, 0, 0, 0, 0, 1, 1, 0 },
130-
{ 1, 0, 0, 0, 1, 1, 0, 0 },
131-
{ 1, 1, 0, 0, 0, 1, 1, 1 },
132-
{ 0, 0, 1, 0, 1, 0, 0, 1 },
133-
{ 1, 0, 0, 0, 0, 0, 1, 1 }
127+
{ 1, 1, 0, 1, 1, 0, 0, 0 },
128+
{ 1, 0, 1, 1, 0, 0, 0, 0 },
129+
{ 1, 1, 1, 0, 0, 1, 1, 1 },
130+
{ 0, 0, 0, 0, 0, 1, 1, 0 },
131+
{ 1, 0, 0, 0, 1, 1, 0, 0 },
132+
{ 1, 1, 0, 0, 0, 1, 1, 1 },
133+
{ 0, 0, 1, 0, 1, 0, 0, 1 },
134+
{ 1, 0, 0, 0, 0, 0, 1, 1 }
134135
};
135-
var expected = new[,]
136+
int[,] expected =
136137
{
137-
{ 1, 1, 0, 1, 1, 0, 0, 0 },
138-
{ 0, 0, 0, 0, 0, 1, 1, 0 },
139-
{ 1, 0, 1, 1, 1, 1, 0, 1 },
140-
{ 1, 0, 0, 0, 0, 0, 0, 1 },
141-
{ 1, 1, 0, 0, 1, 0, 0, 1 },
142-
{ 1, 1, 0, 1, 0, 0, 0, 1 },
143-
{ 1, 0, 0, 0, 0, 0, 0, 0 },
144-
{ 0, 0, 0, 0, 0, 0, 1, 1 }
138+
{ 1, 1, 0, 1, 1, 0, 0, 0 },
139+
{ 0, 0, 0, 0, 0, 1, 1, 0 },
140+
{ 1, 0, 1, 1, 1, 1, 0, 1 },
141+
{ 1, 0, 0, 0, 0, 0, 0, 1 },
142+
{ 1, 1, 0, 0, 1, 0, 0, 1 },
143+
{ 1, 1, 0, 1, 0, 0, 0, 1 },
144+
{ 1, 0, 0, 0, 0, 0, 0, 0 },
145+
{ 0, 0, 0, 0, 0, 0, 1, 1 }
145146
};
146147
Assert.Equal(expected, GameOfLife.Tick(matrix));
147148
}

0 commit comments

Comments
 (0)