-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOfLifeShould.cs
73 lines (60 loc) · 1.9 KB
/
GameOfLifeShould.cs
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
using NUnit.Framework;
namespace GameOfLife;
public class GameOfLifeShould
{
private GameOfLife game;
[SetUp]
public void Setup()
{
game = new GameOfLife();
}
[Test]
public void Nothing()
{
var input =
"...\n" +
"...\n" +
"...\n";
string output = game.Process(input);
Assert.AreEqual(input, output);
}
// 1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
[TestCase("...\n.*.\n.*.\n")]
[TestCase(".*.\n...\n.*.\n")]
public void UndercrowdedCellShouldDie(string input)
{
string expectedResult =
"...\n" +
"...\n" +
"...\n";
Assert.AreEqual(expectedResult, game.Process(input));
}
// 2. Any live cell with more than three live neighbours dies, as if by overcrowding.
[TestCase("***\n**.\n...\n", "*.*\n*.*\n...\n")]
[TestCase("**.\n**.\n.*.\n", "**.\n..*\n**.\n")]
public void OvercrowdedCellShouldDie(string input, string expectedResult)
{
Assert.AreEqual(expectedResult, game.Process(input));
}
// 3. Any live cell with two or three live neighbours lives on to the next generation.
[TestCase("**.\n*..\n.**\n", "**.\n*.*\n.*.\n")]
[TestCase("**.\n*..\n...\n", "**.\n**.\n...\n")]
public void CellWithTwoOrThreeFriendsShouldSurvive(string input, string expectedResult)
{
Assert.AreEqual(expectedResult, game.Process(input));
}
// 4. Any dead cell with exactly three live neighbours becomes a live cell.
[Test]
public void OvercrowdedDeadCellShouldResurrect()
{
var input =
".*.\n" +
"**.\n" +
"...\n";
string expectedResult =
"**.\n" +
"**.\n" +
"...\n";
Assert.AreEqual(expectedResult, game.Process(input));
}
}