コード例 #1
0
        public void LoadLabirintTest()
        {
            //arrange
            const string labirintFilePath = @"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\labirint_test1.txt";

            var expectedMap = new MazeCell[3, 4];

            expectedMap[0, 0] = new MazeCell(0, 0, CellType.Wall);
            expectedMap[0, 1] = new MazeCell(1, 0, CellType.Wall);
            expectedMap[0, 2] = new MazeCell(2, 0, CellType.Wall);
            expectedMap[0, 3] = new MazeCell(3, 0, CellType.Wall);
            expectedMap[1, 0] = new MazeCell(0, 1, CellType.Wall);
            expectedMap[1, 1] = new MazeCell(1, 1, CellType.Start);
            expectedMap[1, 2] = new MazeCell(2, 1, CellType.Exit);
            expectedMap[1, 3] = new MazeCell(3, 1, CellType.Wall);
            expectedMap[2, 0] = new MazeCell(0, 2, CellType.Wall);
            expectedMap[2, 1] = new MazeCell(1, 2, CellType.Wall);
            expectedMap[2, 2] = new MazeCell(2, 2, CellType.Wall);
            expectedMap[2, 3] = new MazeCell(3, 2, CellType.Wall);

            //act
            var io = new MazeIO();

            io.ReadMazeFromFileTaskAsync(labirintFilePath);
            var actualMap = io.CreateMazeMatrix().MazeCells;

            //assert

            CollectionAssert.AreEqual(expectedMap, actualMap, "Матрицы не равны");
        }
コード例 #2
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");
        }
コード例 #3
0
        public void LoadLabirint_NoLinesInFile()
        {
            //arrange
            var labirintPath = @"C:\Users\ia_no\Source\Repos\CodeTechnologyLabs_course3\MazeOperations.Tests\TestInput\empty_maze.txt";

            var expectedSolution = "Файл не содержит ни одной строки";
            //act
            var io   = new MazeIO();
            var task = io.ReadMazeFromFileTaskAsync(labirintPath);

            //assert
            Assert.AreEqual(expectedSolution, task.Exception.InnerException.Message);
        }
コード例 #4
0
        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;
        }
コード例 #5
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
        }