示例#1
0
文件: GridTest.cs 项目: khanhl/GoL
 public void giveInvalidRow_shouldRaiseException()
 {
     int rows = 0;
     int columns = 1;
     Grid target = new Grid(rows, columns);
     Assert.Fail("Expected exception");
 }
示例#2
0
文件: GridTest.cs 项目: khanhl/GoL
 public void GridConstructorPositiveTest()
 {
     int rows = 2;
     int columns = 2;
     Grid target = new Grid(rows, columns);
     Assert.AreEqual(target.RowCount, 2);
     Assert.AreEqual(target.ColumnCount, 2);
 }
示例#3
0
文件: Game.cs 项目: khanhl/GoL
        /// <summary>
        /// Create input and output grids by using rows and column count and initialize Accessible cells.
        /// Accessible Cells are cells which can be traversed from inner grid cells or outer grid cells i.e. virtual cells used for expanding grid
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        public Game(int rows, int columns)
        {
            if (rows <= 0 || columns <= 0) throw new ArgumentOutOfRangeException("Row and Column size must be greater than zero");

            _inputGrid = new Grid(rows, columns);
            _outputGrid = new Grid(rows, columns);
            AccessibleCell.InitializeAccessibleCells();
        }
示例#4
0
        /// <summary>
        /// Get the coordinates with respect to grid and return the Cell type enum
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="Coordinates"></param>
        /// <returns>returns CellTypeEnum</returns>
        public static CellTypeEnum GetCellType(Grid grid, Coordinates Coordinates)
        {
            if ((Coordinates.X < -1 || Coordinates.X > grid.RowCount) || (Coordinates.Y < -1 || Coordinates.Y > grid.ColumnCount))
            {
                throw new ArgumentOutOfRangeException("Invalid Index value: must be greater than or equal to minus one and less than or equal to Row count");
            }

            CellTypeEnum enumCellType = CellTypeEnum.None;

            if (Coordinates.X == 0 && Coordinates.Y == 0)
                enumCellType = CellTypeEnum.TopLeftCorner;
            else if (Coordinates.X == 0 && Coordinates.Y == grid.ColumnCount - 1)
                enumCellType = CellTypeEnum.TopRightCorner;
            else if (Coordinates.X == grid.RowCount - 1 && Coordinates.Y == 0)
                enumCellType = CellTypeEnum.BottomLeftCorner;
            else if (Coordinates.X == grid.RowCount - 1 && Coordinates.Y == grid.ColumnCount - 1)
                enumCellType = CellTypeEnum.BottomRightCorner;
            else if (Coordinates.X == 0 && (Coordinates.Y > 0 && Coordinates.Y < grid.ColumnCount - 1))
                enumCellType = CellTypeEnum.TopSide;
            else if (Coordinates.X == grid.RowCount - 1 && (Coordinates.Y > 0 && Coordinates.Y < grid.ColumnCount - 1))
                enumCellType = CellTypeEnum.BottomSide;
            else if ((Coordinates.X > 0 && Coordinates.X < grid.RowCount - 1) && Coordinates.Y == 0)
                enumCellType = CellTypeEnum.LeftSide;
            else if ((Coordinates.X > 0 && Coordinates.X < grid.RowCount - 1) && Coordinates.Y == grid.ColumnCount - 1)
                enumCellType = CellTypeEnum.RightSide;
            else if ((Coordinates.X > 0 && Coordinates.X < grid.RowCount - 1) && (Coordinates.Y > 0 && Coordinates.Y < grid.ColumnCount - 1))
                enumCellType = CellTypeEnum.Center;
            else if (Coordinates.X == -1 && (Coordinates.Y > 0 && Coordinates.Y < grid.ColumnCount - 1))
                enumCellType = CellTypeEnum.OuterTopSide;
            else if ((Coordinates.X > 0 && Coordinates.X < grid.RowCount - 1) && Coordinates.Y == grid.ColumnCount)
                enumCellType = CellTypeEnum.OuterRightSide;
            else if (Coordinates.X == grid.RowCount && (Coordinates.Y > 0 && Coordinates.Y < grid.ColumnCount - 1))
                enumCellType = CellTypeEnum.OuterBottomSide;
            else if ((Coordinates.X > 0 && Coordinates.X < grid.RowCount - 1) && Coordinates.Y == -1)
                enumCellType = CellTypeEnum.OuterLeftSide;

            return enumCellType;
        }
示例#5
0
文件: GridTest.cs 项目: khanhl/GoL
 public void GridConstructorExceptionTest1()
 {
     int rows = -1;
     int columns = 0;
     Grid target = new Grid(rows, columns);
 }