Esempio n. 1
0
 public void AstarMoveDownTest1()
 {
     // arrange
     var a = new Astar(new EuclidianHeuristic(), new DownAdjacement());
     var grid = GetUnpassableMiddleGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(1, gridHeight - 1);
     // act
     var path = a.Process(grid, from, to); ;
     // assert
     Assert.IsTrue(path.Count() == 0, "Empty path");
 }
Esempio n. 2
0
 public void AstarEmptyPathTestManh()
 {
     // arrange
     var a = new Astar(new ManhattanHeuristic(), new StraightAdjacement());
     var grid = GetUnpassableMiddleGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(gridWidth - 1, gridHeight - 1);
     // act
     var path = a.Process(grid, from, to); ;
     // assert
     Assert.IsTrue(path.Count() == 0, "Empty path");
 }
Esempio n. 3
0
 public void PathLenTest1()
 {
     //arrange
     var a = new Astar(new EuclidianHeuristic(), new StraightAdjacement());
     var d = new Dijkstra();
     var grid = GetTestGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(0, gridHeight - 1);
     //act
     var path1 = a.Process(grid, from, to);
     var path2 = d.Process(grid, from, to);
     //compare
     Assert.IsTrue(PathLen(path1) == PathLen(path2), "path length");
 }
Esempio n. 4
0
 public void PathEndpointsTest()
 {
     //arrange
     var a = new Astar(new EuclidianHeuristic(), new StraightAdjacement());
     var d = new Dijkstra();
     var grid = GetTestGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(0, gridHeight - 1);
     //act
     var path1 = a.Process(grid, from, to);
     var path2 = d.Process(grid, from, to);
     //compare
     Assert.IsTrue(path1.First().Coordinates == path2.First().Coordinates, "first coord");
     Assert.IsTrue(path1.Last().Coordinates == path2.Last().Coordinates, "last coord");
 }
Esempio n. 5
0
        public void PathLenTest3()
        {
            var a = new Astar(new EuclidianHeuristic(), new StraightAdjacement());
            var d = new Dijkstra();
            double l1, l2;
            ICell[,] grid;
            IEnumerable<ICell> path1, path2;
            Coordinates from = new Coordinates(0, 0), to = new Coordinates(gridWidth - 1, gridHeight - 1);

            grid = GetRandomGrid(16);
            path1 = a.Process(grid, from, to);
            path2 = d.Process(grid, from, to);
            l1 = PathLen(path1);
            l2 = PathLen(path2);
            Assert.IsTrue(l1 == l2, "path length. A* = " + l1.ToString() + " Dijkstra = " + l2.ToString());
        }
Esempio n. 6
0
        public void RandomPathTest()
        {
            var rand = new Random();
            var a = new Astar(new EuclidianHeuristic(), new StraightAdjacement());
            var d = new Dijkstra();
            double l1 = 0, l2 = 0;
            ICell[,] grid;
            IEnumerable<ICell> path1, path2;
            Coordinates from = new Coordinates(0, 0), to = new Coordinates(gridWidth - 1, gridHeight - 1);

            int max = 10000;
            int count = 0;
            for (int i = 0; i < max; ++i)
            {
                grid = GetRandomGrid(rand);
                path1 = a.Process(grid, from, to);
                path2 = d.Process(grid, from, to);
                l1 = PathLen(path1);
                l2 = PathLen(path2);
                if (Math.Abs(l1 / l2) < 1.5)
                    ++count;
            }
            Assert.IsTrue(count >= max * 0.6, "too many fails:" + (max - count).ToString());
        }
Esempio n. 7
0
 public void AstarMoveDownTest2()
 {
     // arrange
     var a = new Astar(new EuclidianHeuristic(), new DownAdjacement());
     var grid = GetUnpassableMiddleGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(0, gridHeight - 1);
     // act
     var path = a.Process(grid, from, to); ;
     // assert
     Assert.IsTrue(path.First().Coordinates == from, "first coord");
     Assert.IsTrue(path.Last().Coordinates == to, "last coord");
 }
Esempio n. 8
0
 public void AstarCreating4()
 {
     var a = new Astar(new EmptyHeuristic(), new EmptyAdjacement());
     Assert.IsFalse(a == null, "Object not created");
 }
Esempio n. 9
0
 public void AstarCreating3()
 {
     var a = new Astar(null, new EmptyAdjacement());
 }
Esempio n. 10
0
 public void AstarCreating2()
 {
     var a = new Astar(new EmptyHeuristic(), null);
 }
Esempio n. 11
0
 public void AstarCreating1()
 {
     var a = new Astar(null, null);
 }
Esempio n. 12
0
 public void AstarSameCoordinatesTestManh()
 {
     // arrange
     var a = new Astar(new ManhattanHeuristic(), new StraightAdjacement());
     var grid = GetUnpassableMiddleGrid();
     var coord = new Coordinates(0, 0);
     // act
     var path = a.Process(grid, coord, coord);
     // assert
     Assert.IsTrue(path.First().Coordinates == coord, "Same-Same: first coord");
     Assert.IsTrue(path.Last().Coordinates == coord, "Same-Same: last coord");
 }
Esempio n. 13
0
 public void AstarPathFoundTestManh()
 {
     //arrange
     var a = new Astar(new ManhattanHeuristic(), new StraightAdjacement());
     var grid = GetUnpassableMiddleGrid();
     Coordinates from = new Coordinates(0, 0), to = new Coordinates(0, gridHeight - 1);
     //act
     var path = a.Process(grid, from, to);
     //assert
     Assert.IsTrue(path.First().Coordinates == from, "LT-LB: first coord");
     Assert.IsTrue(path.Last().Coordinates == to, "LT-LB: last coord");
 }