public void CanSetAliveCells() { var game = new Game(2); game.GiveBirth(0, 0); game.GiveBirth(0, 1); AssertThat.AreEqual(@"xx ..", game); }
public void TestWithTwoNeighbors() { var game = new Game(3); game.GiveBirth(0, 0); game.GiveBirth(0, 1); game.GiveBirth(1, 1); game.Step(); Assert.IsTrue(game.Cells[1, 1]); }
public void AnyLiveCellWithThreeNeighborsLives() { var game = new Game(3); game.GiveBirth(0, 0); game.GiveBirth(0, 2); game.GiveBirth(2, 0); game.GiveBirth(1, 1); game.Step(); Assert.IsTrue(game[1, 1].IsAlive); }
public void AnyLiveCellWithOneNeighborsDies() { var game = new Game(3); game.GiveBirth(0, 0); game.GiveBirth(1, 1); game.Step(); AssertThat.AreEqual(@"... ... ...", game); }
public void TestAllCellsWithThreeNeighbors() { var game = new Game(3); game.GiveBirth(0, 0); game.GiveBirth(2, 0); game.GiveBirth(0, 2); game.Step(); var expected = new[,] { {false, false, false}, {false, true, false}, {false, false, false} }; CollectionAssert.AreEqual(expected, game.Cells); }
public Game Reconstitute(DataObjects.Game doGame) { var game = new Game(doGame.Size, doGame.Name); foreach (var cell in doGame.Cells) { game.GiveBirth(cell.Y, cell.X); } return game; }
public void GameIsSaved() { var database = new InMemoryDatabase(); var game = new Game(2, "Test game"); game.GiveBirth(0, 0); game.GiveBirth(0, 1); new GameService().Save(game, database); var session = database.OpenSession(); var gameFromDb = session.Query<Infrastructure.DataObjects.Game>().Single(_ => _.Name == "Test game"); Assert.AreEqual(2, gameFromDb.Cells.Count()); Assert.AreEqual(0, gameFromDb.Cells.First().X); Assert.AreEqual(0, gameFromDb.Cells.First().Y); Assert.AreEqual(1, gameFromDb.Cells.Last().X); Assert.AreEqual(0, gameFromDb.Cells.Last().Y); }
public static Game AsGame(this string gameRepresentation, string name = "") { var lines = gameRepresentation.Split(new[] {Environment.NewLine, "\n"}, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(_ => _.Trim().ToCharArray()); var game = new Game(lines.Count, name); for (var row = 0; row < lines.Count; row++) { var line = lines[row]; for (var column = 0; column < line.Count(); column++) { if (line[column] == 'x' || line[column] == 'X') { game.GiveBirth(row, column); } } } return game; }