Exemple #1
0
        public void GetLabirintSolutionTest()
        {
            //arrange
            var labirintPath = @"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\GetMazeSolutionTextNew.txt";
            var io           = new MazeIO();

            io.ReadMazeFromFileTaskAsync(labirintPath);
            var map        = io.CreateMazeMatrix();
            var startPlace = map.StartCellPosition;
            var exitPlace  = map.ExitCellPosition;

            var expectedSolution = new List <MazeCell>
            {
                new MazeCell(1, 1),
                new MazeCell(2, 1),
                new MazeCell(3, 1),
                new MazeCell(4, 1),
                new MazeCell(5, 1),
                new MazeCell(5, 2),
                new MazeCell(6, 2),
                new MazeCell(7, 2),
                new MazeCell(7, 1),
            };

            //act
            var solver = new MazePathFinder(map);

            var actualSolution = solver.GetCellsPath(startPlace, exitPlace);

            //assert
            CollectionAssert.AreEqual(expectedSolution, actualSolution, new MazeCellComparer(),
                                      $"\nExpected:{expectedSolution.Count}\nActual:{actualSolution.Count}\n");
        }
        private async Task InfluteMazeControl(string dialogFilePath)
        {
            MazeIO = new MazeIO();
            await MazeIO.ReadMazeFromFileTaskAsync(dialogFilePath);

            Maze = MazeIO.CreateMazeMatrix();
            var finder    = new MazePathFinder(Maze);
            var startCell = Maze.StartCellPosition;
            var exitCell  = Maze.ExitCellPosition;

            SolutionList      = finder.GetCellsPath(startCell, exitCell);
            StartCellPosition = startCell;
            ExitCellPosition  = exitCell;
        }
Exemple #3
0
        public void GetLabirintSolutionTest_NoSolution()
        {
            //arrange
            var labirintPath = @"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\solver_test_no_solution.txt";
            var io           = new MazeIO();

            io.ReadMazeFromFileTaskAsync(labirintPath);
            var map        = io.CreateMazeMatrix();
            var startPlace = map.StartCellPosition;
            var exitPlace  = map.ExitCellPosition;

            var expectedSolution = new List <MazeCell>();
            //act
            var solver = new MazePathFinder(map);

            //assert
            Assert.ThrowsException <SolutionNotExistException>(() => solver.GetCellsPath(startPlace, exitPlace));
        }
        //[DataRow(@"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\labirint5.txt", false)]
        //[DataRow(@"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\output.txt", true)]
        //[DataRow(@"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\test_outOfRange.txt", false)]
        #endregion
        public void RunSolutionTest_Solution_true(string labirintFilePath, bool correct)
        {
            //arrange
            var expectedPassed = correct;
            var io             = new MazeIO();

            io.ReadMazeFromFileTaskAsync(labirintFilePath);
            var map        = io.CreateMazeMatrix();
            var startPlace = map.StartCellPosition;
            var exitPlace  = map.ExitCellPosition;
            //act
            var solver       = new MazePathFinder(map);
            var tester       = new MazePathSolutionTester(map, startPlace, exitPlace);
            var solution     = solver.GetCellsPath(startPlace, exitPlace);
            var actualPassed = tester.RunSolutionTest(solution);

            //assert
            Assert.AreEqual(expectedPassed, actualPassed);
        }
Exemple #5
0
        public void GetLabirintSolutionTest_Source_equal_Destination_place()
        {
            //arrange
            var labirintPath = @"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\labirintD.txt";
            var io           = new MazeIO();

            io.ReadMazeFromFileTaskAsync(labirintPath);
            var map              = io.CreateMazeMatrix();
            var startPlace       = map.StartCellPosition;
            var expectedSolution = "Точка начала совпадает с точкой выхода";

            //act
            var solver = new MazePathFinder(map);
            var ex     = Assert.ThrowsException <StartEqualsFinishException>(
                () => solver.GetCellsPath(startPlace, startPlace));

            //assert
            Assert.AreEqual(expectedSolution, ex.Message);
        }
        private bool Run()
        {
            MazeInputOutput = new MazeIO();
            MazeInputOutput.ReadMazeFromFileTaskAsync(_mazeMapFilePath);
            try
            {
                Maze       = MazeInputOutput.CreateMazeMatrix();
                StartPlace = Maze.StartCellPosition;
                ExitPlace  = Maze.ExitCellPosition;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Tester = new MazePathSolutionTester(Maze, StartPlace, ExitPlace);

            Finder = new MazePathFinder(Maze);

            Solution = Finder.GetCellsPath(StartPlace, ExitPlace);

            if (Tester.RunSolutionTest(Solution))
            {
                Console.OutputEncoding = System.Text.Encoding.Unicode;
                PrintMazeMap(Maze.Height, Maze.Width, Maze.MazeCells);
                for (var i = 0; i < Solution.Count - 1; i++)
                {
                    PrintSolutionPath(Solution[i], Solution[i + 1]);
                }
                PrintStartFinishLabels(StartPlace, ExitPlace);
            }
            else
            {
                return(false);
            }
            return(true);
        }