Пример #1
0
        public void CanRemoveEdge()
        {
            var graph = ScriptableObject.CreateInstance <Graph>();

            var node1 = new TestNodeA();
            var node2 = new TestNodeA();
            var node3 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddNode(node3);

            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            graph.AddEdge(
                node1.GetPort("Output"),
                node3.GetPort("Input")
                );

            graph.RemoveEdge(
                node1.GetPort("Output"),
                node3.GetPort("Input")
                );

            Assert.AreEqual(1, node1.GetPort("Output").connections.Count);
            Assert.AreEqual(0, node3.GetPort("Input").connections.Count);
        }
Пример #2
0
        public void RemovingPortsAlsoRemovesEdges()
        {
            var graph = ScriptableObject.CreateInstance <Graph>();

            var node1 = new TestNodeA();
            var node2 = new TestNodeA();
            var node3 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddNode(node3);

            var portToRemove = node2.GetPort("Input");

            // Edge that should be deleted
            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            // Unaffected edge
            graph.AddEdge(
                node2.GetPort("Output"),
                node3.GetPort("Input")
                );

            node2.RemovePort(portToRemove);

            Assert.AreEqual(0, node1.GetPort("Output").connections.Count);
            Assert.AreEqual(1, node2.GetPort("Output").connections.Count);
            Assert.AreEqual(1, node3.GetPort("Input").connections.Count);
        }
Пример #3
0
        public void RemovingNodeAlsoRemovesEdges()
        {
            var graph = ScriptableObject.CreateInstance <Graph>();

            var node1        = new TestNodeA();
            var nodeToRemove = new TestNodeA();
            var node2        = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(nodeToRemove);
            graph.AddNode(node2);

            graph.AddEdge(
                node1.GetPort("Output"),
                nodeToRemove.GetPort("Input")
                );

            graph.AddEdge(
                node2.GetPort("Output"),
                nodeToRemove.GetPort("Input")
                );

            graph.RemoveNode(nodeToRemove);

            Assert.AreEqual(0, node1.GetPort("Output").connections.Count);
            Assert.AreEqual(0, node2.GetPort("Output").connections.Count);

            Assert.AreEqual(0, nodeToRemove.GetPort("Input").connections.Count);
        }
        public void GetInputValueAggregatesMultipleOutputs()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();
            var node1 = new TestNodeA {
                aValue1 = 1
            };
            var node2 = new TestNodeA {
                aValue1 = 2
            };
            var node3 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddNode(node3);

            graph.AddEdge(
                node1.GetPort("Output"),
                node3.GetPort("Input")
                );

            graph.AddEdge(
                node2.GetPort("Output"),
                node3.GetPort("Input")
                );

            var expected = new int[] { 2, 3 };
            var actual   = node3.GetInputValues <int>("Input").ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
        public void CanUndoAddEdge()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();
            var node1 = new TestNodeA();
            var node2 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);

            Undo.RegisterCompleteObjectUndo(graph, "Add Edge 1 -> 2");

            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            Undo.PerformUndo();

            Assert.AreEqual(2, graph.Nodes.Count);
            Assert.AreEqual(graph.Nodes.ElementAt(0).ID, node1.ID);
            Assert.AreEqual(graph.Nodes.ElementAt(1).ID, node2.ID);

            Assert.AreEqual(0, graph.Nodes.ElementAt(0).GetPort("Output").ConnectionCount);
            Assert.AreEqual(0, graph.Nodes.ElementAt(1).GetPort("Input").ConnectionCount);
        }
Пример #6
0
        public void GetUnknownPortReturnsNull()
        {
            var node = new TestNodeA();

            var actual = node.GetPort("Bad Port");

            Assert.IsNull(actual);
        }
        public void ReturnsNullOnInvalidPortName()
        {
            var node = new TestNodeA();

            var actual = node.GetPort("Bad Port");

            Assert.IsNull(actual);
        }
        public void CanAddPorts()
        {
            var node  = new TestNodeA();
            var port1 = new OutputPort <float> {
                Name = "Test 1"
            };
            var port2 = new OutputPort <float> {
                Name = "Test 2"
            };

            node.AddPort(port1);
            node.AddPort(port2);

            // Test Node A comes with 2 ports by default
            Assert.AreEqual(4, node.Ports.Count);
            Assert.AreSame(port1, node.GetPort("Test 1"));
            Assert.AreSame(port2, node.GetPort("Test 2"));
        }
        public void CanAddEdges()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();

            var node1 = new TestNodeA();
            var node2 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            var outputsFromNode1 = node1.GetPort("Output").ConnectedPorts;
            var inputsToNode2    = node2.GetPort("Input").ConnectedPorts;

            Assert.AreEqual(1, outputsFromNode1.Count());
            Assert.AreEqual(1, inputsToNode2.Count());

            Assert.AreSame(node2, outputsFromNode1.First().Node);
            Assert.AreSame(node1, inputsToNode2.First().Node);
        }
        public void UndoAddNodeDoesNotAffectUnrelatedConnections()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();
            var node1 = new TestNodeA();
            var node2 = new TestNodeA();
            var node3 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            Undo.RegisterCompleteObjectUndo(graph, "Add Node 3 and Edge 2 -> 3");

            graph.AddNode(node3);

            graph.AddEdge(
                node2.GetPort("Output"),
                node3.GetPort("Input")
                );

            Undo.PerformUndo();

            // Make sure an undo operation did not destroy unrelated connections and
            // cleanly reset connections to their previous state (no dangling edges)
            var outputs = graph.Nodes.ElementAt(0).GetPort("Output").ConnectedPorts;
            var inputs  = graph.Nodes.ElementAt(1).GetPort("Input").ConnectedPorts;

            Assert.AreEqual(2, graph.Nodes.Count);
            Assert.AreEqual(1, outputs.Count());
            Assert.AreEqual(1, inputs.Count());

            Assert.AreSame(graph.Nodes.ElementAt(0), inputs.First().Node);
            Assert.AreSame(graph.Nodes.ElementAt(1), outputs.First().Node);
        }
Пример #11
0
        public void CanGetPorts()
        {
            var node = new TestNodeA();

            node.AddPort(new Port {
                name = "Test 1"
            });
            node.AddPort(new Port {
                name = "Test 2"
            });

            var actual = node.GetPort("Test 2");

            Assert.AreSame(node, actual.node);
            Assert.AreSame("Test 2", actual.name);
        }
        public void CanGetPorts()
        {
            var node = new TestNodeA();

            node.AddPort(new OutputPort <float> {
                Name = "Test 1"
            });
            node.AddPort(new OutputPort <float> {
                Name = "Test 2"
            });

            var actual = node.GetPort("Test 2");

            Assert.AreSame(node, actual.Node);
            Assert.AreSame("Test 2", actual.Name);
        }
        public void GetInputValueReadsInputConnection()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();
            var node1 = new TestNodeA();
            var node2 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);

            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            var actual   = node2.GetInputValue("Input", 2);
            var expected = 5 + 1; // node1's OnRequestValue() result

            Assert.AreEqual(expected, actual);
        }
        public void CannotAddDuplicateEdges()
        {
            var graph  = ScriptableObject.CreateInstance <TestGraph>();
            var node1  = new TestNodeA();
            var node2  = new TestNodeA();
            var output = node1.GetPort("Output");
            var input  = node2.GetPort("Input");

            graph.AddNode(node1);
            graph.AddNode(node2);

            graph.AddEdge(output, input);

            // Add duplicate
            graph.AddEdge(output, input);

            // Make sure there's only one edge between the nodes
            Assert.AreEqual(1, output.ConnectionCount);
            Assert.AreEqual(1, input.ConnectionCount);
        }
        public void GetOutputValueReadsInputPortValues()
        {
            var graph = ScriptableObject.CreateInstance <TestGraph>();
            var node1 = new TestNodeA();
            var node2 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);

            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            var actual = node2.GetOutputValue <int>("Output");

            // node1.OnRequestValue() + node2.OnRequestValue()
            var expected = (5 + 1) + 1;

            Assert.AreEqual(expected, actual);
        }
Пример #16
0
        public void CanAddEdges()
        {
            var graph = ScriptableObject.CreateInstance <Graph>();

            var node1 = new TestNodeA();
            var node2 = new TestNodeA();

            graph.AddNode(node1);
            graph.AddNode(node2);
            graph.AddEdge(
                node1.GetPort("Output"),
                node2.GetPort("Input")
                );

            var outputs = graph.nodes[0].GetPort("Output").ConnectedPorts;
            var inputs  = graph.nodes[1].GetPort("Input").ConnectedPorts;

            Assert.AreEqual(1, outputs.Length);
            Assert.AreEqual(1, inputs.Length);

            Assert.AreSame(graph.nodes[0], inputs[0].node);
            Assert.AreSame(graph.nodes[1], outputs[0].node);
        }