Exemplo n.º 1
0
        public void ReturnCorrectPath_OnEmptyDungeon()
        {
            var textMap = new[]
            {
                "P ",
                "CE"
            };
            var map = Map.FromLines(textMap);

            var path = DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new[] { MoveDirection.Down, MoveDirection.Right }, path);
        }
Exemplo n.º 2
0
        public void ReturnEmptyPath_WhenNoPathToExit()
        {
            var textMap = new[]
            {
                "P#",
                "#E"
            };
            var map = Map.FromLines(textMap);

            var path = DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new MoveDirection[0], path);
        }
Exemplo n.º 3
0
        public void ReturnPathToExit_IfNoChests()
        {
            var textMap = new[]
            {
                "PE",
                "  "
            };
            var map = Map.FromLines(textMap);

            var path = DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new[] { MoveDirection.Right }, path);
        }
Exemplo n.º 4
0
        public void ReturnCorrectPaths_OnEmptyDungeon()
        {
            var textMap = new[]
            {
                "P ",
                "C "
            };
            var map             = Map.FromLines(textMap);
            var expectedLengths = new[] { 2 };

            var paths = GetPaths(map);

            AssertPaths(paths, map, expectedLengths);
        }
Exemplo n.º 5
0
        public void ReturnNoPaths_WhenNoPathsToChests()
        {
            var textMap = new[]
            {
                "P ",
                "##",
                "C "
            };
            var map = Map.FromLines(textMap);

            var paths = GetPaths(map);

            Assert.IsEmpty(paths);
        }
Exemplo n.º 6
0
        public void Return_ShortestPath2()
        {
            var textMap = new[]
            {
                "ECC",
                " P ",
                "CCC"
            };
            var map = Map.FromLines(textMap);

            var path = DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new[] { MoveDirection.Up, MoveDirection.Left }, path);
        }
Exemplo n.º 7
0
        public void ReturnPathToExit_IfChestIsUnreachable()
        {
            var textMap = new[]
            {
                "PE#",
                "###",
                "C  "
            };
            var map = Map.FromLines(textMap);

            var path = DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new[] { MoveDirection.Right }, path);
        }
Exemplo n.º 8
0
        public void ReturnCorrectPath_OnSimpleDungeon()
        {
            var textMap = new[]
            {
                "P #",
                "#C#",
                "E  "
            };
            var map = Map.FromLines(textMap);

            var path = My_DungeonTask.FindShortestPath(map);

            Assert.AreEqual(new[] { MoveDirection.Right, MoveDirection.Down, MoveDirection.Down, MoveDirection.Left }, path);
        }
Exemplo n.º 9
0
        public void Return_ShortestPaths2()
        {
            var textMap = new[]
            {
                " C ",
                "CPC",
                " C "
            };
            var map             = Map.FromLines(textMap);
            var expectedLengths = new[] { 2, 2, 2, 2 };

            var paths = GetPaths(map);

            AssertPaths(paths, map, expectedLengths);
        }
Exemplo n.º 10
0
        public void Return_ShortestPaths1()
        {
            var textMap = new[]
            {
                "   ",
                " P ",
                " C "
            };
            var map             = Map.FromLines(textMap);
            var expectedLengths = new[] { 2 };

            var paths = GetPaths(map);

            AreValidPaths(paths, map, expectedLengths);
        }
Exemplo n.º 11
0
        public void ReturnCorrectPaths_OnSimpleDungeon()
        {
            var textMap = new[]
            {
                "P #",
                "# #",
                "C  "
            };
            var map             = Map.FromLines(textMap);
            var expectedLengths = new[] { 5 };

            var paths = GetPaths(map);

            AreValidPaths(paths, map, expectedLengths);
        }
Exemplo n.º 12
0
        public void Return_ShortestPaths3()
        {
            var textMap = new[]
            {
                "CC",
                "CP",
            };
            var map             = Map.FromLines(textMap);
            var expectedLengths = new[] { 3, 2, 2 };

            var paths = GetPaths(map)
                        .OrderByDescending(x => x.Count)
                        .ToArray();

            AssertPaths(paths, map, expectedLengths);
        }
Exemplo n.º 13
0
        public void WorksCorrect_ShortestPaths_OnManyCalls()
        {
            var miniMap = Map.FromLines(new[]

            {
                " C ",
                "CPC",
                " C "
            });
            var miniPaths = GetPaths(miniMap);

            AssertPaths(miniPaths, miniMap, new[] { 2, 2, 2, 2 });

            var map   = Map.FromText(Properties.Resources.BigTestDungeon);
            var paths = GetPaths(map)
                        .OrderByDescending(x => x.Count)
                        .ToArray();

            AssertPaths(paths, map, new[] { 170, 156, 144, 137, 84 });
        }