Beispiel #1
0
        public void AStarShortestPath()
        {
            var run = new MoveTypeEdgeData {
                moveType = MoveType.Run
            };
            var jump = new MoveTypeEdgeData {
                moveType = MoveType.Jump
            };
            var wallJump = new MoveTypeEdgeData {
                moveType = MoveType.WallJump
            };

            var myGraph = new UndirectedWeightedGraph <char, MoveTypeEdgeData>();

            myGraph.AddNodes('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');
            myGraph.AddEdges(
                ('a', 'b', 2, run),
                ('a', 'c', 3, run),
                ('a', 'e', 4, wallJump),
                ('b', 'd', 2, jump),
                ('b', 'e', 1, run),
                ('c', 'g', 4, jump),
                ('c', 'h', 11, run),
                ('d', 'c', 3, jump),
                ('d', 'f', 2, run),
                ('d', 'h', 3, wallJump),
                ('e', 'f', 5, run),
                ('f', 'h', 6, wallJump),
                ('g', 'h', 7, run)
                );

            myGraph
            .AStarShortestPath('a', 'h', (x, y) => 1)
            .Select(edge => myGraph.EdgeData(edge.Item1, edge.Item2))
            .Should()
            .ContainInOrder(
                run, jump, wallJump
                )
            .And
            .HaveCount(3);

            // have to call Count() because otherwise the lazy evaluation wont trigger
            myGraph.Invoking(x => x.AStarShortestPath('a', 'z', (x, y) => 1).Count()).Should().Throw <System.ArgumentException>();
        }