Exemplo n.º 1
0
        public void MazeIsSolvedAndSolutionIsComplete()
        {
            // Test that start of solution path IsStartPoint and end IsFinishPoint
            const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png";
            var          mazeReader        = new MazeReaderUtility(mazeImageFilePath);
            var          mazeToTest        = mazeReader.ReadInMazeImage();
            var          mazeSolution      = new BruteForceMazeSolution(mazeToTest);

            mazeSolution.SolveMaze();

            Assert.IsTrue(mazeSolution.PathToSolveMaze.First().MazeGridpoint.IsStartPoint);
            Assert.IsTrue(mazeSolution.PathToSolveMaze.Last().MazeGridpoint.IsFinishPoint);

            // Test that solution path is connected all the way through, distance between each point is unity
            var lastSolutionElement = mazeSolution.PathToSolveMaze.First();

            foreach (var solutionElement in mazeSolution.PathToSolveMaze.Skip(1))
            {
                var lastCoordinate = lastSolutionElement.MazeGridpoint.Position;
                var thisCoordinate = solutionElement.MazeGridpoint.Position;

                Assert.AreEqual(lastCoordinate.Distance(thisCoordinate), 1.0, 0.000001);

                lastSolutionElement = solutionElement;
            }
        }
        public void SolveMaze_SuperSimpleMazeCannotBeSolved_ThrowsException()
        {
            const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMazeCannotBeSolved.png";
            var          mazeReader        = new MazeReaderUtility(mazeImageFilePath);
            var          mazeToTest        = mazeReader.ReadInMazeImage();
            var          mazeSolution      = new BruteForceMazeSolution(mazeToTest);

            mazeSolution.SolveMaze();
        }
        public void SolveMaze_UltraTinyMaze_NumberOfStepsToSolveAsExpected()
        {
            const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png";
            var          mazeReader        = new MazeReaderUtility(mazeImageFilePath);
            var          mazeToTest        = mazeReader.ReadInMazeImage();
            var          mazeSolution      = new BruteForceMazeSolution(mazeToTest);

            mazeSolution.SolveMaze();

            var stepsToSolveMaze = mazeSolution.PathToSolveMaze.Count();

            Assert.AreEqual(stepsToSolveMaze, 95);

            var gridpointsVisited = mazeSolution.MazeToSolve.MazeGridpoints.Values.Count(m => m.HasBeenVisited);

            Assert.AreEqual(gridpointsVisited, 166);
        }
Exemplo n.º 4
0
        public void PreTreatmentMakesMazeEasierToSolve()
        {
            const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png";
            var          mazeReader        = new MazeReaderUtility(mazeImageFilePath);
            var          mazeToTest        = mazeReader.ReadInMazeImage();
            var          mazeSolution      = new BruteForceMazeSolution(mazeToTest);

            mazeSolution.SolveMaze();

            var stepsToSolveMazeWithoutPreTreatment = mazeSolution.PathToSolveMaze.Count();

            mazeToTest   = mazeReader.ReadInMazeImage();
            mazeSolution = new BruteForceMazeSolution(mazeToTest);
            mazeSolution.PreTreatmentLogics.Add(new RemoveRedundantWhiteSpace(mazeToTest));

            mazeSolution.SolveMaze();

            var stepsToSolveMazeWithPreTreatment = mazeSolution.PathToSolveMaze.Count();

            Assert.IsTrue(stepsToSolveMazeWithPreTreatment < stepsToSolveMazeWithoutPreTreatment);
        }