Пример #1
0
        public void IsBoardComplete_When_Valid_Should_Be_True()
        {
            Board board = new Board(new List <List <int> >
            {
                new List <int> {
                    5, 2, 9, 4, 1, 7, 8, 3, 6
                },
                new List <int> {
                    8, 1, 3, 2, 5, 6, 9, 7, 4
                },
                new List <int> {
                    4, 7, 6, 8, 9, 3, 2, 5, 1
                },
                new List <int> {
                    6, 4, 1, 5, 2, 8, 3, 9, 7
                },
                new List <int> {
                    3, 5, 7, 6, 4, 9, 1, 8, 2
                },
                new List <int> {
                    9, 8, 2, 3, 7, 1, 6, 4, 5
                },
                new List <int> {
                    7, 3, 8, 1, 6, 5, 4, 2, 9
                },
                new List <int> {
                    1, 9, 4, 7, 3, 2, 5, 6, 8
                },
                new List <int> {
                    2, 6, 5, 9, 8, 4, 7, 1, 3
                }
            });

            Assert.True(BoardValidator.IsBoardComplete(board));
        }
Пример #2
0
        public void IsBoardComplete_When_Invalid_Should_Be_False()
        {
            Board board = new Board(new List <List <int> >
            {
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                },
                new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                }
            });

            Assert.False(BoardValidator.IsBoardComplete(board));
        }
Пример #3
0
        public void IsBoardValid_Should_Be_False_When_Duplicates_In_Box()
        {
            Board board = new Board(new List <List <int> >
            {
                new List <int> {
                    5, 2, 9, 4, 1, 7, 8, 3, 6
                },
                new List <int> {
                    8, 2, 3, 0, 5, 6, 9, 7, 4
                },
                new List <int> {
                    4, 7, 6, 8, 9, 3, 2, 5, 1
                },
                new List <int> {
                    6, 4, 1, 5, 2, 8, 3, 9, 7
                },
                new List <int> {
                    3, 5, 7, 6, 4, 9, 1, 8, 2
                },
                new List <int> {
                    9, 8, 2, 3, 7, 1, 6, 4, 5
                },
                new List <int> {
                    7, 3, 8, 1, 6, 5, 4, 2, 9
                },
                new List <int> {
                    1, 9, 4, 7, 3, 2, 5, 6, 8
                },
                new List <int> {
                    2, 6, 5, 9, 8, 4, 7, 1, 3
                }
            });

            Assert.False(BoardValidator.IsBoardValid(board));
        }
Пример #4
0
        public void ValidateNoPositionOvelap_WhenNoValidPiecePositionY_ThenThrowException()
        {
            // Arrange
            var input = new List <(PieceType Type, Position Pos)>()
            {
                (PieceType.Knight, new Position(8, 0)),
            };

            var validator = new BoardValidator();

            try
            {
                // Act
                validator.Validate(input);
                Assert.Fail();
            }

            catch (ArgumentException e)
            {
                // Assert
                Assert.AreEqual("The Knight has invalid position: 8,0", e.Message);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Пример #5
0
        public void ValidateNoPositionOvelap_WhenPiecesOverlapping_ThenThrowException()
        {
            // Arrange
            var input = new List <(PieceType Type, Position Pos)>()
            {
                (PieceType.Knight, new Position(7, 7)),
                (PieceType.Knight, new Position(7, 7)),
            };

            var validator = new BoardValidator();

            try
            {
                // Act
                validator.Validate(input);
                Assert.Fail();
            }

            catch (ArgumentException e)
            {
                // Assert
                Assert.AreEqual("The Knight occupied the position of another piece. The dublicate positon is 7,7", e.Message);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Пример #6
0
 public ShipLocationGenerator()
 {
     _boardValidator     = new BoardValidator();
     _board              = new GameBoard();
     _shipLocations      = new List <ShipLocation>(GameSettings.Instance.TotalNumberOfShips);
     _destroyerShipLimit = GameSettings.Instance.NumberOfDestroyerShips;
     _battleShipLimit    = GameSettings.Instance.NumberOfBattleShips;
 }
Пример #7
0
        public void IsLineComplete(IEnumerable <int> line, bool expected)
        {
            List <int> realLine = line.ToList();

            bool actual = BoardValidator.IsLineComplete(realLine);

            Assert.Equal(expected, actual);
        }
Пример #8
0
        public void When_validating_board_and_it_is_smaller_then_two_by_two_then_return_error()
        {
            var board = new Board {
                Rows = 1, Columns = 1
            };
            var boardValidator = new BoardValidator();

            var results = boardValidator.Validate(board);

            results.Errors.Count.Should().Be(2);
            results.Errors[0].ErrorMessage.Should().Be("Board rows should be greater or equal 2.");
            results.Errors[1].ErrorMessage.Should().Be("Board columns should be greater or equal 2.");
        }
Пример #9
0
        public void ValidateNoPositionOvelap_WhenValidData_ThenPassValidation()
        {
            // Arrange
            var input = new List <(PieceType Type, Position Pos)>()
            {
                (PieceType.Knight, new Position(8, 8)),
                (PieceType.Knight, new Position(1, 1)),
            };

            var validator = new BoardValidator();

            // Act
            validator.Validate(input);
        }
        public void BoxNeighboursSame_False()
        {
            //arrange
            int[] cellvalues = new int[] { 1, 8, 2, 0, 0, 0, 0, 0, 4, 8, 0, 7, 1, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 4, 0, 1, 0, 0, 0,
                                           6, 3, 9, 7, 0, 0, 0, 4, 0, 0, 6, 2, 0, 7, 3, 0, 1, 3, 0, 0, 0, 8, 9, 6, 0, 0, 7, 5, 0, 4, 3, 1, 8, 6, 0, 1,
                                           8, 0, 0, 5, 0, 0, 0, 0, 6, 4, 0, 0, 2, 0, 0, 0 };
            SudokuBoard    board     = new SudokuBoard(cellvalues);
            BoardValidator validator = new BoardValidator();

            //act
            Result result = validator.Validate(board);

            //assert
            Assert.IsFalse(result.IsSuccess);
        }
Пример #11
0
        public static void TestPawnCounts(string fen, BoardExceptionType expectedResult)
        {
            var actual = BoardExceptionType.None;

            try
            {
                var board     = FenReader.Translate(fen);
                var validator = new BoardValidator();
                validator.Validate(board);
            }
            catch (BoardException exc)
            {
                actual = exc.ExceptionType;
            }

            Assert.AreEqual(expectedResult, actual);
        }
Пример #12
0
        public static void ValidateCheck(string fen, BoardExceptionType expectedException)
        {
            var actual = BoardExceptionType.None;

            try
            {
                var board          = FenReader.Translate(fen);
                var boardValidator = new BoardValidator();
                boardValidator.Validate(board);
            }
            catch (BoardException be)
            {
                actual = be.ExceptionType;
            }

            Assert.AreEqual(expectedException, actual);
        }
Пример #13
0
        public void Setup()
        {
            _mockCellSetValidator = Fixture.Mock <ICellSetValidator>();

            _boardValidator = Fixture.Create <BoardValidator>();
        }
Пример #14
0
 public Board() : base(BoardConstants.FenStartingPosition)
 {
     Occupancy = new ulong[2][];
     InitializeOccupancy();
     BoardValidator = new BoardValidator();
 }