Example #1
0
 public Test(Topology.SortingAlgorithm algo, ComputeType computingType, uint traversalMask, uint alternateMask)
 {
     Cache        = new Topology.TraversalCache(0, traversalMask, alternateMask);
     Nodes        = new NativeList <Node>(10, Allocator.Temp);
     TestDatabase = new TopologyTestDatabase(Allocator.Temp);
     m_Options    = Topology.CacheAPI.ComputationOptions.Create(computeJobified: computingType == ComputeType.Jobified);
     Version      = Topology.CacheAPI.VersionTracker.Create();
     m_Algorithm  = algo;
 }
Example #2
0
        public void InputOutputCountsAreCorrect()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var node = topoDB.CreateNode();

                Assert.AreEqual(0, topoDB.GetInputs(node).GetEnumerator().Count());
                Assert.AreEqual(0, topoDB.GetOutputs(node).GetEnumerator().Count());
            }
        }
Example #3
0
        public void GetInputsOutputs_WorksFor_ActualNode()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var node = topoDB.CreateNode();

                topoDB.GetInputs(node);
                topoDB.GetOutputs(node);
            }
        }
Example #4
0
        public void CanWalkNodesThroughConnections()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();

                topoDB.Connect(a, k_OutputPorts[0], b, k_InputPorts[0]);

                Assert.AreEqual(b, topoDB.GetOutputs(a).GetNthConnection(k_OutputPorts[0], 0));
                Assert.AreEqual(a, topoDB.GetInputs(b).GetNthConnection(k_InputPorts[0], 0));
            }
        }
Example #5
0
        public void CanDisconnectAllTopologyNodes()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();
                var c = topoDB.CreateNode();

                for (int i = 0; i < 3; ++i)
                {
                    OutputPort outPort = k_OutputPorts[i];
                    InputPort  inPort  = k_InputPorts[i];

                    topoDB.Connect(b, outPort, a, inPort);
                    topoDB.Connect(c, outPort, b, inPort);

                    Assert.AreEqual(0, topoDB.GetOutputs(a)[outPort].Count());
                    Assert.AreEqual(1, topoDB.GetInputs(a)[inPort].Count());
                    Assert.AreEqual(1, topoDB.GetOutputs(b)[outPort].Count());
                    Assert.AreEqual(1, topoDB.GetInputs(b)[inPort].Count());
                    Assert.AreEqual(1, topoDB.GetOutputs(c)[outPort].Count());
                    Assert.AreEqual(0, topoDB.GetInputs(c)[inPort].Count());
                }

                topoDB.DisconnectAll(b);

                foreach (var node in new[] { a, b, c })
                {
                    var inputs         = topoDB.GetInputs(node);
                    var inputPortCount = inputs.GetEnumerator().Count();
                    for (int i = 0; i < inputPortCount; ++i)
                    {
                        Assert.AreEqual(0, inputs[k_InputPorts[i]].Count());
                    }

                    var outputs         = topoDB.GetOutputs(node);
                    var outputPortCount = outputs.GetEnumerator().Count();
                    for (int i = 0; i < outputPortCount; ++i)
                    {
                        Assert.AreEqual(0, outputs[k_OutputPorts[i]].Count());
                    }
                }
            }
        }
Example #6
0
        public void CanWalk_InputsAndOutputs_ForSinglyConnected()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();
                var c = topoDB.CreateNode();

                topoDB.Connect(b, k_OutputPorts[0], a, k_InputPorts[0]);
                topoDB.Connect(c, k_OutputPorts[0], a, k_InputPorts[2]);

                Assert.AreEqual(b, topoDB.GetInputs(a).GetNthConnection(k_InputPorts[0], 0));
                Assert.AreEqual(0, topoDB.GetInputs(a)[k_InputPorts[1]].Count());
                Assert.AreEqual(c, topoDB.GetInputs(a).GetNthConnection(k_InputPorts[2], 0));

                Assert.AreEqual(a, topoDB.GetOutputs(c).GetNthConnection(k_OutputPorts[0], 0));
                Assert.AreEqual(a, topoDB.GetOutputs(b).GetNthConnection(k_OutputPorts[0], 0));
            }
        }
Example #7
0
        public void CanCreateDirectedCyclicGraph_AndWalkInCircles()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();

                topoDB.Connect(a, k_OutputPorts[0], b, k_InputPorts[0]);
                topoDB.Connect(b, k_OutputPorts[0], a, k_InputPorts[0]);

                for (int i = 0; i < 100; ++i)
                {
                    var temp = topoDB.GetOutputs(a).GetNthConnection(k_OutputPorts[0], 0);
                    Assert.AreEqual(b, temp);
                    Assert.AreEqual(a, topoDB.GetInputs(b).GetNthConnection(k_InputPorts[0], 0));
                    b = a;
                    a = temp;
                }
            }
        }
Example #8
0
        public void CanDisconnectTopologyNodes()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();

                Assert.AreEqual(0, topoDB.GetOutputs(a)[k_OutputPorts[0]].Count());
                Assert.AreEqual(0, topoDB.GetInputs(b)[k_InputPorts[0]].Count());

                topoDB.Connect(a, k_OutputPorts[0], b, k_InputPorts[0]);

                Assert.AreEqual(1, topoDB.GetOutputs(a)[k_OutputPorts[0]].Count());
                Assert.AreEqual(1, topoDB.GetInputs(b)[k_InputPorts[0]].Count());

                topoDB.Disconnect(a, k_OutputPorts[0], b, k_InputPorts[0]);

                Assert.AreEqual(0, topoDB.GetOutputs(a)[k_OutputPorts[0]].Count());
                Assert.AreEqual(0, topoDB.GetInputs(b)[k_InputPorts[0]].Count());
            }
        }
Example #9
0
        [Test] public void CanWalk_InputsAndOutputs_ForDoublyConnectedInput()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();
                var c = topoDB.CreateNode();

                topoDB.Connect(b, k_OutputPorts[0], a, k_InputPorts[0]);
                topoDB.Connect(c, k_OutputPorts[0], a, k_InputPorts[0]);

                var filteredPorts = topoDB.GetInputs(a)[k_InputPorts[0]];

                foreach (var node in filteredPorts)
                {
                    Assert.That(node, Is.EqualTo(b).Or.EqualTo(c));
                }

                Assert.AreEqual(a, topoDB.GetOutputs(c).GetNthConnection(k_OutputPorts[0], 0));
                Assert.AreEqual(a, topoDB.GetOutputs(b).GetNthConnection(k_OutputPorts[0], 0));
            }
        }
Example #10
0
        public void CanConnectTwoEdges_ToOnePort()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();
                var c = topoDB.CreateNode();

                topoDB.Connect(a, k_OutputPorts[0], b, k_InputPorts[0]);
                topoDB.Connect(a, k_OutputPorts[0], c, k_InputPorts[0]);

                // TODO: Fix: Topology is not stable with regards to insertion order.

                Assert.AreEqual(c, topoDB.GetOutputs(a).GetNthConnection(k_OutputPorts[0], 0));
                Assert.AreEqual(b, topoDB.GetOutputs(a).GetNthConnection(k_OutputPorts[0], 1));

                var byPort = topoDB.GetOutputs(a)[k_OutputPorts[0]];
                byPort.MoveNext();
                Assert.AreEqual(c, byPort.Current);
                byPort.MoveNext();
                Assert.AreEqual(b, byPort.Current);
            }
        }
Example #11
0
        public void CanChainWalk_ForwardsAndBackwards()
        {
            using (var topoDB = new TopologyTestDatabase(Allocator.Persistent))
            {
                var a = topoDB.CreateNode();
                var b = topoDB.CreateNode();
                var c = topoDB.CreateNode();

                topoDB.Connect(b, k_OutputPorts[0], a, k_InputPorts[0]);
                topoDB.Connect(c, k_OutputPorts[0], b, k_InputPorts[0]);

                Assert.AreEqual(
                    a,
                    topoDB.GetOutputs(topoDB.GetOutputs(c).GetNthConnection(k_OutputPorts[0], 0))
                    .GetNthConnection(k_OutputPorts[0], 0)
                    );

                Assert.AreEqual(
                    c,
                    topoDB.GetInputs(topoDB.GetInputs(a).GetNthConnection(k_InputPorts[0], 0))
                    .GetNthConnection(k_InputPorts[0], 0)
                    );
            }
        }