Exemple #1
0
 public void giveInvalidRow_shouldRaiseException()
 {
     int rows = 0;
     int columns = 1;
     Grid target = new Grid(rows, columns);
     Assert.Fail("Expected exception");
 }
Exemple #2
0
 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);
 }
Exemple #3
0
        /// <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();
        }
Exemple #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;
        }
Exemple #5
0
 public void GridConstructorExceptionTest1()
 {
     int rows = -1;
     int columns = 0;
     Grid target = new Grid(rows, columns);
 }