public void TestRemoveNodeFromBaseMaterialGraphCleansEdges() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); var createdEdge = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var edge = graph.edges.FirstOrDefault(); Assert.AreEqual(createdEdge, edge); graph.RemoveNode(outputNode); Assert.AreEqual(1, graph.GetNodes <INode>().Count()); Assert.AreEqual(0, graph.edges.Count()); Assert.AreEqual(inputNode, graph.GetNodes <INode>().FirstOrDefault()); }
public void TestConectionToSameInputReplacesOldInput() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); var createdEdge = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var edge = graph.edges.FirstOrDefault(); Assert.AreEqual(createdEdge, edge); var createdEdge2 = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var edge2 = graph.edges.FirstOrDefault(); Assert.AreEqual(createdEdge2, edge2); }
public void TestCanConnectAndTraverseTwoNodesOnBaseMaterialGraph() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); var createdEdge = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var edge = graph.edges.FirstOrDefault(); Assert.AreEqual(createdEdge, edge); var foundOutputNode = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid); var foundOutputSlot = foundOutputNode.FindOutputSlot <ISlot>(edge.outputSlot.slotId); Assert.AreEqual(outputNode, foundOutputNode); Assert.IsNotNull(foundOutputSlot); var foundInputNode = graph.GetNodeFromGuid(edge.inputSlot.nodeGuid); var foundInputSlot = foundInputNode.FindInputSlot <ISlot>(edge.inputSlot.slotId); Assert.AreEqual(inputNode, foundInputNode); Assert.IsNotNull(foundInputSlot); }
public void TestCanFindSlotReferenceOnTestNode() { var node = new TestableNode(); Assert.AreEqual(6, node.GetSlots <ISlot>().Count()); Assert.IsNotNull(node.GetSlotReference(TestableNode.Input0)); Assert.IsNotNull(node.GetSlotReference(TestableNode.Output0)); Assert.Throws <ArgumentException>(() => node.GetSlotReference(555)); }
public void TestCanFindSlotOnTestNode() { var node = new TestableNode(); Assert.AreEqual(6, node.GetSlots <ISlot>().Count()); Assert.IsNotNull(node.FindInputSlot <ISlot>(TestableNode.Input0)); Assert.IsNull(node.FindInputSlot <ISlot>(TestableNode.Output0)); Assert.IsNotNull(node.FindOutputSlot <ISlot>(TestableNode.Output0)); Assert.IsNull(node.FindOutputSlot <ISlot>(TestableNode.Input0)); Assert.IsNotNull(node.FindSlot <ISlot>(TestableNode.Input0)); Assert.IsNotNull(node.FindSlot <ISlot>(TestableNode.Output0)); Assert.IsNull(node.FindSlot <ISlot>(555)); }
public void TestCanConnectAndTraverseThreeNodesOnBaseMaterialGraph() { var graph = new GraphData(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var middleNode = new TestableNode(); graph.AddNode(middleNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(3, graph.GetNodes <AbstractMaterialNode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), middleNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); graph.Connect(middleNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(2, graph.edges.Count()); var edgesOnMiddleNode = NodeUtils.GetAllEdges(middleNode); Assert.AreEqual(2, edgesOnMiddleNode.Count()); outputNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive); middleNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive); inputNode.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitActive); List <AbstractMaterialNode> result = new List <AbstractMaterialNode>(); NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode); Assert.AreEqual(3, result.Count); result.Clear(); NodeUtils.DepthFirstCollectNodesFromNode(result, inputNode, NodeUtils.IncludeSelf.Exclude); Assert.AreEqual(2, result.Count); result.Clear(); NodeUtils.DepthFirstCollectNodesFromNode(result, null); Assert.AreEqual(0, result.Count); }
public void TestCanGetEdgesOnBaseMaterialGraphFromSlotReference() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); Assert.AreEqual(1, graph.GetEdges(inputNode.GetSlotReference(TestableNode.Input0)).Count()); Assert.AreEqual(1, graph.GetEdges(outputNode.GetSlotReference(TestableNode.Output0)).Count()); Assert.Throws <ArgumentException>(() => outputNode.GetSlotReference(666)); }
public void TestRemovingElementsFromBaseMaterialGraph() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); graph.RemoveElements(graph.GetNodes <INode>(), graph.edges); Assert.AreEqual(0, graph.GetNodes <INode>().Count()); Assert.AreEqual(0, graph.edges.Count()); }
public void TestRemovingNodeRemovesConectedEdgesOnBaseMaterialGraph() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); graph.RemoveNode(graph.GetNodes <INode>().FirstOrDefault()); Assert.AreEqual(1, graph.GetNodes <INode>().Count()); Assert.AreEqual(0, graph.edges.Count()); }
public void TestCanNotConnectTwoInputSlotsOnBaseMaterialGraph() { var graph = new TestMaterialGraph(); var inputNode = new TestableNode(); graph.AddNode(inputNode); var inputNode2 = new TestableNode(); graph.AddNode(inputNode2); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); var createdEdge = graph.Connect(inputNode.GetSlotReference(TestableNode.Input0), inputNode2.GetSlotReference(TestableNode.Input0)); Assert.IsNull(createdEdge); Assert.AreEqual(0, graph.edges.Count()); }
public void TestCanNotConnectToNullSlot() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); var createdEdge2 = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), new SlotReference(Guid.NewGuid(), 666)); Assert.AreEqual(0, graph.edges.Count()); Assert.IsNull(createdEdge2); }
public void TestRemovingElementsFromBaseMaterialGraph() { var graph = new GraphData(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <AbstractMaterialNode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); graph.RemoveElements(graph.GetNodes <AbstractMaterialNode>().ToArray(), graph.edges.ToArray(), new GroupData[] {}, new StickyNoteData[] {}); Assert.AreEqual(0, graph.GetNodes <AbstractMaterialNode>().Count()); Assert.AreEqual(0, graph.edges.Count()); }
public void TestCanNotConnectTwoOuputSlotsOnBaseMaterialGraph() { var graph = new GraphData(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var outputNode2 = new TestableNode(); graph.AddNode(outputNode2); Assert.AreEqual(2, graph.GetNodes <AbstractMaterialNode>().Count()); var createdEdge = graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), outputNode2.GetSlotReference(TestableNode.Output0)); Assert.IsNull(createdEdge); Assert.AreEqual(0, graph.edges.Count()); }
public void TestRemovingSlotRemovesConnectedEdges() { var graph = new TestNodeGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.GetEdges().Count); outputNode.RemoveSlot(TestableNode.Output0); Assert.AreEqual(0, graph.GetEdges().Count); }
public void TestCanRemoveSlotsWithNonMathingNameFromTestNode() { var graph = new TestMaterialGraph(); var node = new TestableNode(); graph.AddNode(node); Assert.AreEqual(6, node.GetSlots <ISlot>().Count()); Assert.AreEqual(3, node.GetInputSlots <ISlot>().Count()); Assert.AreEqual(3, node.GetOutputSlots <ISlot>().Count()); node.RemoveSlotsNameNotMatching(new[] { TestableNode.Input1 }); Assert.AreEqual(1, node.GetSlots <ISlot>().Count()); Assert.AreEqual(1, node.GetInputSlots <ISlot>().Count()); Assert.AreEqual(0, node.GetOutputSlots <ISlot>().Count()); Assert.IsNull(node.FindInputSlot <ISlot>(TestableNode.Input0)); Assert.IsNotNull(node.FindInputSlot <ISlot>(TestableNode.Input1)); Assert.IsNull(node.FindInputSlot <ISlot>(TestableNode.Input2)); }
public void TestGetInputsWithNoConnection() { var graph = new TestMaterialGraph(); var outputNode = new TestableNode(); graph.AddNode(outputNode); var inputNode = new TestableNode(); graph.AddNode(inputNode); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(outputNode.GetSlotReference(TestableNode.Output0), inputNode.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var slots = inputNode.GetInputsWithNoConnection(); Assert.AreEqual(2, slots.Count()); CollectionAssert.AreEqual(new[] { TestableNode.Input1, TestableNode.Input2 }, slots.Select(x => x.id)); }
public void TestCyclicConnectionsAreNotAllowedOnGraph() { var graph = new TestMaterialGraph(); var nodeA = new TestableNode(); graph.AddNode(nodeA); var nodeB = new TestableNode(); graph.AddNode(nodeB); Assert.AreEqual(2, graph.GetNodes <INode>().Count()); graph.Connect(nodeA.GetSlotReference(TestableNode.Output0), nodeB.GetSlotReference(TestableNode.Input0)); Assert.AreEqual(1, graph.edges.Count()); var edge = graph.Connect(nodeB.GetSlotReference(TestableNode.Output0), nodeA.GetSlotReference(TestableNode.Input0)); Assert.IsNull(edge); Assert.AreEqual(1, graph.edges.Count()); }
public void TestExceptionIfBadNodeConfigurationWorks() { var node = new TestableNode(); Assert.DoesNotThrow( () => NodeUtils.SlotConfigurationExceptionIfBadConfiguration( node, new[] { TestableNode.Input0, TestableNode.Input1, TestableNode.Input2 }, new[] { TestableNode.Output0, TestableNode.Output1, TestableNode.Output2, }) ); Assert.Throws <SlotConfigurationException>( () => NodeUtils.SlotConfigurationExceptionIfBadConfiguration( node, new[] { 666, TestableNode.Input1, TestableNode.Input2 }, new[] { TestableNode.Output0, TestableNode.Output1, TestableNode.Output2, }) ); Assert.Throws <SlotConfigurationException>( () => NodeUtils.SlotConfigurationExceptionIfBadConfiguration( node, new[] { TestableNode.Input0, TestableNode.Input1, TestableNode.Input2 }, new[] { 666, TestableNode.Output1, TestableNode.Output2, }) ); Assert.DoesNotThrow( () => NodeUtils.SlotConfigurationExceptionIfBadConfiguration( node, new[] { TestableNode.Input0 }, new[] { TestableNode.Output0 }) ); }