Ejemplo n.º 1
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");
 }
Ejemplo n.º 2
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");
 }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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());
        }