Пример #1
0
        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);
        }
Пример #2
0
        public void GetNeighboringCells_GridIsOnlyOneCell_ReturnsEmptyCollection()
        {
            var grid   = new CellularGrid(1, 1, new InitRule());
            var actual = grid.GetNeighboringCells(0, 0);

            CollectionAssert.IsEmpty(actual);
        }
Пример #3
0
        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);
        }
Пример #4
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);
        }
Пример #5
0
        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);
        }
Пример #6
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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 public void GetNeighboringCells_NegativeArguments_ThrowsException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _grid.GetNeighboringCells(-1, -1));
     Assert.Throws <ArgumentOutOfRangeException>(() => _grid.GetNeighboringCells(1, -1));
     Assert.Throws <ArgumentOutOfRangeException>(() => _grid.GetNeighboringCells(-1, 1));
 }