|
|
|
|
|
|
var graph = new SerializableGraph(); |
|
|
|
|
|
|
|
Assert.AreEqual(0, graph.edges.Count()); |
|
|
|
Assert.AreEqual(0, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(0, graph.GetNodes<INode>().Count()); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
Assert.AreEqual("Test Node", graph.nodes.FirstOrDefault().name); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.AreEqual("Test Node", graph.GetNodes<INode>().FirstOrDefault().name); |
|
|
|
Assert.AreEqual(graph, node.owner); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
graph.RemoveNode(graph.nodes.FirstOrDefault()); |
|
|
|
Assert.AreEqual(0, graph.nodes.Count()); |
|
|
|
graph.RemoveNode(graph.GetNodes<INode>().FirstOrDefault()); |
|
|
|
Assert.AreEqual(0, graph.GetNodes<INode>().Count()); |
|
|
|
private class NoDeleteNode : SerializableNode |
|
|
|
[Test] |
|
|
|
public void TestRemoveNodeFromSerializableGraphCleansEdges() |
|
|
|
public NoDeleteNode(SerializableGraph theOwner) : base(theOwner) |
|
|
|
{} |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var outputSlot = new SerializableSlot("output", "output", SlotType.Output, 0); |
|
|
|
outputNode.AddSlot(outputSlot); |
|
|
|
graph.AddNode(outputNode); |
|
|
|
|
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
var inputSlot = new SerializableSlot("input", "input", SlotType.Input, 0); |
|
|
|
inputNode.AddSlot(inputSlot); |
|
|
|
graph.AddNode(inputNode); |
|
|
|
|
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
var createdEdge = graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input")); |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
private class NoDeleteNode : SerializableNode |
|
|
|
{ |
|
|
|
public override bool canDeleteNode { get { return false; } } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var node = new NoDeleteNode(graph); |
|
|
|
var node = new NoDeleteNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
graph.RemoveNode(graph.nodes.FirstOrDefault()); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
graph.RemoveNode(graph.GetNodes<INode>().FirstOrDefault()); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.IsNotNull(graph.GetNodeFromGuid(node.guid)); |
|
|
|
Assert.IsNull(graph.GetNodeFromGuid(Guid.NewGuid())); |
|
|
|
} |
|
|
|
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
var found = graph.nodes.FirstOrDefault(); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
var found = graph.GetNodes<INode>().FirstOrDefault(); |
|
|
|
Assert.AreEqual(1, found.inputSlots.Count()); |
|
|
|
Assert.AreEqual("input", found.inputSlots.FirstOrDefault().name); |
|
|
|
Assert.AreEqual(1, found.outputSlots.Count()); |
|
|
|
|
|
|
[Test] |
|
|
|
public void TestCanRemoveSlotFromSerializableNode() |
|
|
|
{ |
|
|
|
var node = new SerializableNode(null); |
|
|
|
var node = new SerializableNode(); |
|
|
|
node.AddSlot(new SerializableSlot("output", "output", SlotType.Output, 0)); |
|
|
|
node.AddSlot(new SerializableSlot("input", "input", SlotType.Input, 0)); |
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
public void TestCanRemoveSlotsWithNonMathingNameFromSerializableNode() |
|
|
|
{ |
|
|
|
var node = new SerializableNode(null); |
|
|
|
var node = new SerializableNode(); |
|
|
|
node.AddSlot(new SerializableSlot("input1", "input", SlotType.Input, 0)); |
|
|
|
node.AddSlot(new SerializableSlot("input2", "input", SlotType.Input, 0)); |
|
|
|
node.AddSlot(new SerializableSlot("input3", "input", SlotType.Input, 0)); |
|
|
|
|
|
|
public void TestCanNotAddDuplicateSlotToSerializableNode() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
var found = graph.nodes.FirstOrDefault(); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
var found = graph.GetNodes<INode>().FirstOrDefault(); |
|
|
|
Assert.AreEqual(0, found.inputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.outputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.slots.Count()); |
|
|
|
|
|
|
public void TestCanUpdateDisplaynameByReaddingSlotToSerializableNode() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
var found = graph.nodes.FirstOrDefault(); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
var found = graph.GetNodes<INode>().FirstOrDefault(); |
|
|
|
Assert.AreEqual(0, found.inputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.outputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.slots.Count()); |
|
|
|
|
|
|
public void TestCanUpdatePriorityByReaddingSlotToSerializableNode() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var node = new SerializableNode(graph); |
|
|
|
var node = new SerializableNode(); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
var found = graph.nodes.FirstOrDefault(); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
var found = graph.GetNodes<INode>().FirstOrDefault(); |
|
|
|
Assert.AreEqual(0, found.inputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.outputSlots.Count()); |
|
|
|
Assert.AreEqual(1, found.slots.Count()); |
|
|
|
|
|
|
[Test] |
|
|
|
public void TestCanFindSlotOnSerializableNode() |
|
|
|
{ |
|
|
|
var node = new SerializableNode(null); |
|
|
|
var node = new SerializableNode(); |
|
|
|
node.AddSlot(new SerializableSlot("output", "output", SlotType.Output, 0)); |
|
|
|
node.AddSlot(new SerializableSlot("input", "input", SlotType.Input, 0)); |
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
public void TestCanFindSlotReferenceOnSerializableNode() |
|
|
|
{ |
|
|
|
var node = new SerializableNode(null); |
|
|
|
var node = new SerializableNode(); |
|
|
|
node.AddSlot(new SerializableSlot("output", "output", SlotType.Output, 0)); |
|
|
|
node.AddSlot(new SerializableSlot("input", "input", SlotType.Input, 0)); |
|
|
|
|
|
|
|
|
|
|
public void TestCanConnectAndTraverseTwoNodesOnSerializableGraph() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
|
|
|
|
|
|
|
|
var createdEdge = graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input")); |
|
|
|
|
|
|
public void TestCanNotConnectTwoOuputSlotsOnSerializableGraph() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var outputNode2 = new SerializableNode(graph); |
|
|
|
var outputNode2 = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
|
|
|
|
var createdEdge = graph.Connect(outputNode.GetSlotReference("output"), outputNode2.GetSlotReference("output")); |
|
|
|
Assert.IsNull(createdEdge); |
|
|
|
|
|
|
public void TestCanNotConnectTwoInputSlotsOnSerializableGraph() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
var inputNode2 = new SerializableNode(graph); |
|
|
|
var inputNode2 = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
|
|
|
|
var createdEdge = graph.Connect(inputNode.GetSlotReference("input"), inputNode2.GetSlotReference("input")); |
|
|
|
Assert.IsNull(createdEdge); |
|
|
|
|
|
|
public void TestRemovingNodeRemovesConectedEdgesOnSerializableGraph() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
graph.RemoveNode(graph.nodes.FirstOrDefault()); |
|
|
|
Assert.AreEqual(1, graph.nodes.Count()); |
|
|
|
graph.RemoveNode(graph.GetNodes<INode>().FirstOrDefault()); |
|
|
|
Assert.AreEqual(1, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.AreEqual(0, graph.edges.Count()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.AreEqual(0, graph.edges.Count()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
graph.RemoveElements(graph.nodes, graph.edges); |
|
|
|
Assert.AreEqual(0, graph.nodes.Count()); |
|
|
|
graph.RemoveElements(graph.GetNodes<INode>(), graph.edges); |
|
|
|
Assert.AreEqual(0, graph.GetNodes<INode>().Count()); |
|
|
|
Assert.AreEqual(0, graph.edges.Count()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input")); |
|
|
|
Assert.AreEqual(1, graph.edges.Count()); |
|
|
|
|
|
|
|
|
|
|
public void TestGetInputsWithNoConnection() |
|
|
|
{ |
|
|
|
var graph = new SerializableGraph(); |
|
|
|
var outputNode = new SerializableNode(graph); |
|
|
|
var outputNode = new SerializableNode(); |
|
|
|
var inputNode = new SerializableNode(graph); |
|
|
|
var inputNode = new SerializableNode(); |
|
|
|
Assert.AreEqual(2, graph.nodes.Count()); |
|
|
|
Assert.AreEqual(2, graph.GetNodes<INode>().Count()); |
|
|
|
graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input")); |
|
|
|
Assert.AreEqual(1, graph.edges.Count()); |
|
|
|
|
|
|
|