Exemplo n.º 1
0
        public void ConnectAsymmetricallyTest()
        {
            var a = new PathNode();
            var b = new PathNode();

            a.ConnectAsymmetrically(b, true);
            Assert.IsTrue(a.Connections.Contains(b));
            Assert.IsFalse(b.Connections.Contains(a));

            a.DisconnectAsymmetrically(b);
            b.ConnectAsymmetrically(a);
            a.ConnectAsymmetrically(b, true);
            Assert.IsTrue(a.Connections.Contains(b));
            Assert.IsFalse(b.Connections.Contains(a));

            a.DisconnectAsymmetrically(b);
            a.ConnectAsymmetrically(b, false);
            Assert.IsTrue(a.Connections.Contains(b));
            Assert.IsFalse(b.Connections.Contains(a));

            a.DisconnectAsymmetrically(b);
            b.ConnectAsymmetrically(a);
            a.ConnectAsymmetrically(b, false);
            Assert.IsTrue(a.Connections.Contains(b));
            Assert.IsTrue(b.Connections.Contains(a));
        }
        public void Test()
        {
            var nodeA = new PathNode();
            var nodeB = new PathNode();
            var nodeC = new PathNode();
            var nodeD = new PathNode();

            nodeA.ConnectAsymmetrically(nodeB);
            nodeB.ConnectAsymmetrically(nodeC);
            nodeC.ConnectAsymmetrically(nodeD);
            // A -> B -> C -> D

            var pathfinder1 = new Pathfinder(new PathRequest(nodeA, nodeB));
            var pathfinder2 = new Pathfinder(new PathRequest(nodeA, nodeC));
            var pathfinder3 = new Pathfinder(new PathRequest(nodeA, nodeD));
            var pathfinder4 = new Pathfinder(new PathRequest(nodeC, nodeA));

            var pathfindingManager = new PathfindingManager();

            pathfindingManager.Pathfinders.AddRange(new[] { pathfinder1, pathfinder2, pathfinder3, pathfinder4 });

            for (var i = 0; i < 10; i++)
            {
                pathfindingManager.Update();
                if (pathfindingManager.Pathfinders.Count >= 4)
                {
                    Assert.Contains(pathfinder1, pathfindingManager.Pathfinders);
                }
                if (pathfindingManager.Pathfinders.Count >= 3)
                {
                    Assert.Contains(pathfinder2, pathfindingManager.Pathfinders);
                }
                if (pathfindingManager.Pathfinders.Count >= 2)
                {
                    Assert.Contains(pathfinder3, pathfindingManager.Pathfinders);
                }
            }
            Assert.Zero(pathfindingManager.Pathfinders.Count);
            Assert.IsTrue(new[] { pathfinder1, pathfinder2, pathfinder3 }.All(pf => pf.State == PathfindingState.Successful));
            Assert.IsTrue(pathfinder4.State == PathfindingState.Failed);
        }