Exemple #1
0
        public void MoveForwardCellTestOk()
        {
            var randomGeneratorService = new RandomGeneratorService();
            var moveMazeCellService    = new MoveMazeCellService(randomGeneratorService);

            MazeCell cellToTest = new MazeCell()
            {
                PositionX = 5, PositionY = 5, LastDirectionMovement = (int)Direction.S
            };

            var resultCell = moveMazeCellService.MoveToNextCell(cellToTest, Direction.S);

            Assert.IsTrue(resultCell.PositionY == cellToTest.PositionY + 1 && resultCell.PositionX == cellToTest.PositionX);

            cellToTest.LastDirectionMovement = (int)Direction.N;
            resultCell = moveMazeCellService.MoveToNextCell(cellToTest, Direction.N);
            Assert.IsTrue(resultCell.PositionY == cellToTest.PositionY - 1 && resultCell.PositionX == cellToTest.PositionX);

            cellToTest.LastDirectionMovement = (int)Direction.W;
            resultCell = moveMazeCellService.MoveToNextCell(cellToTest, Direction.W);
            Assert.IsTrue(resultCell.PositionY == cellToTest.PositionY && resultCell.PositionX == cellToTest.PositionX - 1);

            cellToTest.LastDirectionMovement = (int)Direction.E;
            resultCell = moveMazeCellService.MoveToNextCell(cellToTest, Direction.E);
            Assert.IsTrue(resultCell.PositionY == cellToTest.PositionY && resultCell.PositionX == cellToTest.PositionX + 1);
        }
        public void CreateEntryAndExitWayPathTestOk()
        {
            var randomGeneratorService = new RandomGeneratorService();
            //moveMazeCellService Should be  mock instead the concrete class. No time to Mock
            var moveMazeCellService = new MoveMazeCellService(randomGeneratorService);
            var mazeSetupService    = new MazeSetupService();
            var generatedMaze       = mazeSetupService.InitializeMaze(10, 10);

            var exitWayServiceTest = new ExitWayService(moveMazeCellService, randomGeneratorService);

            exitWayServiceTest.CreateEntryAndExitWayPath(10, 10, ref generatedMaze);

            var entryCell = (from MazeCell cell in generatedMaze
                             where cell.Value == (int)MazeCellValueEnum.Entry
                             select cell).FirstOrDefault();

            var exitCell = (from MazeCell cell in generatedMaze
                            where cell.Value == (int)MazeCellValueEnum.Exit
                            select cell).FirstOrDefault();

            Assert.IsNotNull(entryCell);
            Assert.IsNotNull(exitCell);
            //Check exit and entry not in the same side
            Assert.IsFalse((entryCell.PositionX == 0 && exitCell.PositionX == entryCell.PositionX) || (entryCell.PositionY == 0 && exitCell.PositionY == entryCell.PositionY));
            Assert.IsFalse((entryCell.PositionX == 9 && exitCell.PositionX == entryCell.PositionX) || (entryCell.PositionY == 9 && exitCell.PositionY == entryCell.PositionY));
        }
Exemple #3
0
        public void CalculateOppositeDirectionTestOk()
        {
            var randomGeneratorService = new RandomGeneratorService();
            var moveMazeCellService    = new MoveMazeCellService(randomGeneratorService);

            Assert.IsTrue(moveMazeCellService.CalculateOppositeDirection(Direction.N) == Direction.S);
            Assert.IsTrue(moveMazeCellService.CalculateOppositeDirection(Direction.S) == Direction.N);
            Assert.IsTrue(moveMazeCellService.CalculateOppositeDirection(Direction.E) == Direction.W);
            Assert.IsTrue(moveMazeCellService.CalculateOppositeDirection(Direction.W) == Direction.E);
        }
Exemple #4
0
        public void MarkMovementMazeTestWhiteSpaceOk()
        {
            var randomGeneratorService = new RandomGeneratorService();
            var mazeSetupService       = new MazeSetupService();
            var moveMazeCellService    = new MoveMazeCellService(randomGeneratorService);
            var generatedMaze          = mazeSetupService.InitializeMaze(10, 10);

            MazeCellValueEnum expectec = MazeCellValueEnum.Empty;
            MazeCell          nextCell = new MazeCell()
            {
                PositionX = 1, PositionY = 1, LastDirectionMovement = (int)Direction.S
            };


            var result = moveMazeCellService.ValidateAndCalculateCellMovementType(nextCell, 10, 10, 9, 9, Direction.S, MazeCellValueEnum.Empty, generatedMaze);

            Assert.IsTrue(expectec == result);
        }
Exemple #5
0
        public void NextRandomDirectionWallTestOk()
        {
            var randomGeneratorService = new RandomGeneratorService();
            var moveMazeCellService    = new MoveMazeCellService(randomGeneratorService);
            var mazeSetupService       = new MazeSetupService();
            var generatedMaze          = mazeSetupService.InitializeMaze(10, 10);

            MazeCell cellToTest = new MazeCell()
            {
                PositionX = 5, PositionY = 5, LastDirectionMovement = (int)Direction.S
            };

            var resultDirection = moveMazeCellService.NextRandomDirectionWall(cellToTest, generatedMaze, Direction.N, false);

            Assert.IsTrue(resultDirection != Direction.N);

            cellToTest.PositionX = 1;
            cellToTest.PositionY = 1;
            resultDirection      = moveMazeCellService.NextRandomDirectionWall(cellToTest, generatedMaze, Direction.S, false);
            Assert.IsTrue(resultDirection == Direction.E);

            cellToTest.PositionX = 8;
            cellToTest.PositionY = 8;
            resultDirection      = moveMazeCellService.NextRandomDirectionWall(cellToTest, generatedMaze, Direction.N, false);
            Assert.IsTrue(resultDirection == Direction.W);

            cellToTest.PositionX = 1;
            cellToTest.PositionY = 8;
            resultDirection      = moveMazeCellService.NextRandomDirectionWall(cellToTest, generatedMaze, Direction.E, false);
            Assert.IsTrue(resultDirection == Direction.N);

            cellToTest.PositionX = 8;
            cellToTest.PositionY = 1;
            resultDirection      = moveMazeCellService.NextRandomDirectionWall(cellToTest, generatedMaze, Direction.W, false);
            Assert.IsTrue(resultDirection == Direction.S);
        }