public void GetNeighboringCells_GridIsSingleRowTargetIsFirstCell_ReturnsSingRightNeighbor() { var grid = new CellularGrid(1, 5, new InitRule()); var neighbors = grid.GetNeighboringCells(0, 0).ToArray(); Assert.AreEqual(neighbors.Single().Column, 1); }
public void GetNeighboringCells_GridIsOnlyOneCell_ReturnsEmptyCollection() { var grid = new CellularGrid(1, 1, new InitRule()); var actual = grid.GetNeighboringCells(0, 0); CollectionAssert.IsEmpty(actual); }
public void GetNeighboringCells_GridIsSingleColumnTargetIsFirstCell_ReturnsSingBelowNeighbor() { var grid = new CellularGrid(5, 1, new InitRule()); var neighbors = grid.GetNeighboringCells(0, 0); Assert.AreEqual(neighbors.Count(), 1); Assert.AreEqual(neighbors.Single().Row, 1); Assert.AreEqual(neighbors.Single().Column, 0); }
public void GetNeighboringCells_GridIsSingleRowTargetIsLastCell_ReturnsSingLeftNeighbor() { var columnCount = 5; var grid = new CellularGrid(1, columnCount, new InitRule()); var lastColumn = columnCount - 1; var neighbors = grid.GetNeighboringCells(0, lastColumn).ToArray(); Assert.AreEqual(neighbors.Count(), 1); Assert.AreEqual(neighbors.Single().Row, 0); Assert.AreEqual(neighbors.Single().Column, lastColumn - 1); }
public void GetNeighboringCells_GridIsSingleColumnCellInMiddle_ReturnsSingleNeighbor() { var grid = new CellularGrid(10, 1, new InitRule()); var targetRow = 5; var neighbors = grid.GetNeighboringCells(targetRow, 0); var rowIndices = new[] { targetRow - 1, targetRow + 1 }; var rowInCount = neighbors.Count(neighbor => rowIndices.Contains(neighbor.Row)); Assert.AreEqual(neighbors.Count(), 2); Assert.AreEqual(rowInCount, 2); }
public void GetNeighboringCells_GridIsSingleColumnTargetIsLastCell_ReturnsSingAboveNeighbor() { var rowCount = 5; var grid = new CellularGrid(rowCount, 1, new InitRule()); var lastRow = rowCount - 1; var neighbors = grid.GetNeighboringCells(lastRow, 0).ToArray(); Assert.AreEqual(neighbors.Count(), 1); Assert.AreEqual(neighbors.Single().Row, lastRow - 1); Assert.AreEqual(neighbors.Single().Column, 0); }
public void GetNeighboringCells_GridIsSingleRowCellInMiddle_ReturnsSingleNeighbor() { var grid = new CellularGrid(1, 10, new InitRule()); var targetCol = 5; var neighbors = grid.GetNeighboringCells(0, targetCol).ToArray(); var colIndices = new[] { targetCol - 1, targetCol + 1 }; var colInCount = neighbors.Count(neighbor => colIndices.Contains(neighbor.Column)); Assert.AreEqual(neighbors.Count(), 2); Assert.AreEqual(colInCount, 2); }
public void CountAliveNeighbors_FourCellsGrid_Return3() { var grid = new CellularGrid(2, 2, null); grid.Cells[0, 1].Revive(); grid.Cells[1, 1].Revive(); grid.Cells[1, 0].Revive(); var count = grid.CountAliveNeighbors(0, 0); Assert.AreEqual(3, count); }
private void MakeNewGrid() { GetSize(); GetSpeed(); _grid = new CellularGrid(_rows, _cols, _initRule) { WrapBorders = borderCheck.Checked }; _grid.Cycled += Grid_Cycled; AddGameOfLifeRules(); canvas.Refresh(); }
public void Setup() { _grid = new CellularGrid(ROWS_COUNT, COLUMNS_COUNT, new InitRule()); }
public bool Condition(Cell cell, CellularGrid grid) { return(cell.Row % 2 == 0 || cell.Column % 3 == 0); }
public bool Condition(Cell cell, CellularGrid grid) { var neighborsAlive = grid.CountAliveNeighbors(cell.Row, cell.Column); return(cell.State == CellState.Alive && (neighborsAlive < 2 || neighborsAlive > 3)); }
public bool Condition(Cell cell, CellularGrid grid) { return((cell.Row == 0 && cell.Column == 2) || (cell.Row == 1 && cell.Column == 3) || (cell.Row == 2 && (cell.Column == 1 || cell.Column == 2 || cell.Column == 3))); }
public bool Condition(Cell cell, CellularGrid grid) { return((cell.Row == cell.Column) || (cell.Row + cell.Column == grid.RowsCount - 1)); }
public bool Condition(Cell cell, CellularGrid grid) { return(false); }
public bool Condition(Cell cell, CellularGrid grid) { return(cell.Column == grid.ColumnsCount / 2 || cell.Row == grid.RowsCount / 2); }