Exemplo n.º 1
0
        /// <summary>
        /// gets a deep copy of the <paramref name="grid"/>
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        public static IGrid<ICell> GetDeepCopy(this IGrid<ICell> grid)
        {
            var gridCopy = new Grid(grid.NumberOfRows, grid.NumberOfColumns);
            foreach (var cell in grid.Cells)
            {
                var cellCopy = new Cell { RowIndex = cell.RowIndex, ColIndex = cell.ColIndex, IsAlive = cell.IsAlive };
                gridCopy.AddCell(cellCopy);
            }

            return gridCopy;
        }
Exemplo n.º 2
0
        public void Test_AddCell_CellHasRowIndexEqualToFour_ThrowsArgumentOutOfRangeException()
        {
            var grid = new Grid(4, 4);
            var cell = new Cell
                           {
                               RowIndex = 4,
                               ColIndex = 1
                           };

            Assert.Throws<ArgumentOutOfRangeException>(() => grid.AddCell(cell),
                                                 "ArgumentOutOfRangeException should be thrown");
        }
Exemplo n.º 3
0
        private static void CreateAndInitializeFivexFiveGridForBlinkerOscillatorPattern()
        {
            FivexFiveGridForBlinkerOscillatorPattern = new Grid(5, 5);

            for (int rowIndex = 0; rowIndex < 5; rowIndex++)
            {
                for (int colIndex = 0; colIndex < 5; colIndex++)
                {
                    var cell = new Cell { RowIndex = rowIndex, ColIndex = colIndex, IsAlive = false };
                    FivexFiveGridForBlinkerOscillatorPattern.AddCell(cell);
                }
            }

            FivexFiveGridForBlinkerOscillatorPattern.GetCellByIndex(2, 1).IsAlive = true;
            FivexFiveGridForBlinkerOscillatorPattern.GetCellByIndex(2, 2).IsAlive = true;
            FivexFiveGridForBlinkerOscillatorPattern.GetCellByIndex(2, 3).IsAlive = true;
        }
Exemplo n.º 4
0
        public void Test_Cells_ValidCellsAreAdded_ReturnsCollectionOfAddedCells()
        {
            var grid = new Grid(2, 2);
            var cell0 = new Cell
            {
                RowIndex = 0,
                ColIndex = 0
            };

            var cell1 = new Cell
            {
                RowIndex = 0,
                ColIndex = 1
            };

            var cell2 = new Cell
            {
                RowIndex = 1,
                ColIndex = 0
            };

            var cell3 = new Cell
            {
                RowIndex = 1,
                ColIndex = 1
            };

            grid.AddCell(cell0);
            grid.AddCell(cell1);
            grid.AddCell(cell2);
            grid.AddCell(cell3);

            var cells = grid.Cells;

            Assert.That(cells.Count(), Is.EqualTo(4), "Count should have been 4");
            Assert.That(cells.ElementAt(0), Is.EqualTo(cell0),
                        "Cell added using AddCell and cell retrieved using Cells should be same");
            Assert.That(cells.ElementAt(1), Is.EqualTo(cell1),
                        "Cell added using AddCell and cell retrieved using Cells should be same");
            Assert.That(cells.ElementAt(2), Is.EqualTo(cell2),
                        "Cell added using AddCell and cell retrieved using Cells should be same");
            Assert.That(cells.ElementAt(3), Is.EqualTo(cell3),
                        "Cell added using AddCell and cell retrieved using Cells should be same");
        }
Exemplo n.º 5
0
        private static void CreateAndInitializeSixxSixGridForToadOscillatorPattern()
        {
            SixxSixGridForToadOscillatorPattern = new Grid(6, 6);

            for (int rowIndex = 0; rowIndex < 6; rowIndex++)
            {
                for (int colIndex = 0; colIndex < 6; colIndex++)
                {
                    var cell = new Cell { RowIndex = rowIndex, ColIndex = colIndex, IsAlive = false };
                    SixxSixGridForToadOscillatorPattern.AddCell(cell);
                }
            }

            SixxSixGridForToadOscillatorPattern.GetCellByIndex(2, 2).IsAlive = true;
            SixxSixGridForToadOscillatorPattern.GetCellByIndex(2, 3).IsAlive = true;
            SixxSixGridForToadOscillatorPattern.GetCellByIndex(2, 4).IsAlive = true;
            SixxSixGridForToadOscillatorPattern.GetCellByIndex(3, 1).IsAlive = true;
            SixxSixGridForToadOscillatorPattern.GetCellByIndex(3, 2).IsAlive = true;
            SixxSixGridForToadOscillatorPattern.GetCellByIndex(3, 3).IsAlive = true;
        }
Exemplo n.º 6
0
        public void Test_GetCellByIndex_ValidCellIsAdded_ReturnsSameCellAddedUsingAddCell()
        {
            var grid = new Grid(4, 4);
            var cell = new Cell
            {
                RowIndex = 2,
                ColIndex = 2
            };

            grid.AddCell(cell);

            var returnedCell = grid.GetCellByIndex(2, 2);

            Assert.That(returnedCell, Is.EqualTo(cell),
                        "Cell added using AddCell and cell retrieved using GetCellByIndex should be same");
        }
Exemplo n.º 7
0
        public void Test_GetCellByIndex_RowIndexEqualToFour_ThrowsArgumentOutOfRangeException()
        {
            var grid = new Grid(4, 4);
            var cell = new Cell
            {
                RowIndex = 1,
                ColIndex = 1
            };
            grid.AddCell(cell);

            Assert.Throws<ArgumentOutOfRangeException>(() => grid.GetCellByIndex(4,1),
                                                 "ArgumentOutOfRangeException should be thrown");
        }