public void Test_CreateNodeFromLoopPort_CreateLoopStack(TestingMode testingMode, GroupingMode groupingMode) { bool inGroupTest = groupingMode == GroupingMode.Grouped; var stack = GraphModel.CreateStack(string.Empty, Vector2.zero); var loopNode = stack.CreateStackedNode <WhileNodeModel>("loop"); var stackCount = GetStackCount(); var group = inGroupTest ? GraphModel.CreateGroupNode(string.Empty, Vector2.zero) : null; TestPrereqActionPostreq(testingMode, () => { Assert.That(GetStackCount(), Is.EqualTo(stackCount)); var portModel = loopNode.OutputPort; Assert.That(portModel.Connected, Is.False); return(new CreateNodeFromLoopPortAction(loopNode.OutputPort, Vector2.zero, groupModel: group)); }, () => { Assert.That(GetStackCount(), Is.EqualTo(stackCount + 1)); var portModel = loopNode.OutputPort; Assert.That(portModel.Connected, Is.True); var connectedStack = portModel.ConnectionPortModels.Single().NodeModel; Assert.That(connectedStack, Is.TypeOf <WhileHeaderModel>()); Assert.That(connectedStack.IsGrouped, Is.EqualTo(inGroupTest)); Assert.That(connectedStack.GroupNodeModel, Is.EqualTo(group)); }); }
public void Test_CreateStackedNodeFromSearcherAction([Values] TestingMode mode) { GraphModel.CreateStack("stack", Vector2.zero).CreateSetPropertyGroupNode(-1); var db = new GraphElementSearcherDatabase(Stencil).AddUnaryOperators().Build(); var item = (StackNodeModelSearcherItem)db.Search("postdecr", out _)[0]; TestPrereqActionPostreq(mode, () => { var stack = GetAllStacks().Single(); Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(stack.NodeModels.Count, Is.EqualTo(1)); return(new CreateStackedNodeFromSearcherAction(stack, 1, item)); }, () => { var stack = GetAllStacks().Single(); Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(stack.NodeModels.Count, Is.EqualTo(2)); var stackedNodes = stack.NodeModels.ToList(); Assert.That(stackedNodes[0], Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(stackedNodes[1], Is.TypeOf <UnaryOperatorNodeModel>()); } ); }
public void Test_MoveNodesFromSeparateStacks([Values] TestingMode mode) { string customPrefix = "InitialStack"; var stack1 = GraphModel.CreateStack(customPrefix + "1", Vector2.zero); var stack2 = GraphModel.CreateStack(customPrefix + "2", Vector2.right * 400f); stack1.CreateStackedNode <Type0FakeNodeModel>("A"); stack1.CreateStackedNode <Type0FakeNodeModel>("B"); stack2.CreateStackedNode <Type0FakeNodeModel>("C"); Vector2 newStackOffset = Vector2.down * 500f; TestPrereqActionPostreq(mode, () => { Assert.That(GetStackCount(), Is.EqualTo(2)); Assert.That(GetAllStacks().All(s => s.Title.StartsWith(customPrefix)), Is.True); var stackMovements = GetAllStacks().Select(s => new StackCreationOptions(s.Position + newStackOffset, s.NodeModels.ToList())); return(new CreateStacksForNodesAction(stackMovements.ToList())); }, () => { Assert.That(GetStackCount(), Is.EqualTo(2)); Assert.That(GetAllStacks().Any(s => s.Title.StartsWith(customPrefix)), Is.False); }); }
public void Test_ChangeStackedNode([Values] TestingMode mode) { var decl = GraphModel.CreateGraphVariableDeclaration("a", TypeHandle.Bool, true); var stackModel = GraphModel.CreateStack(string.Empty, Vector2.zero); var set = stackModel.CreateStackedNode <SetVariableNodeModel>("set"); var v1 = GraphModel.CreateVariableNode(decl, Vector2.left); var v2 = GraphModel.CreateVariableNode(decl, Vector2.left); GraphModel.CreateEdge(set.InstancePort, v1.OutputPort); GraphModel.CreateEdge(set.ValuePort, v2.OutputPort); var db = new GraphElementSearcherDatabase(Stencil).AddNodesWithSearcherItemAttribute().Build(); var item = (StackNodeModelSearcherItem)db.Search("log", out _)[0]; TestPrereqActionPostreq(mode, () => { Assert.That(stackModel.NodeModels.Count, Is.EqualTo(1)); Assert.That(stackModel.NodeModels.Single(), Is.TypeOf <SetVariableNodeModel>()); set = (SetVariableNodeModel)stackModel.NodeModels.Single(); Assert.That(v1.OutputPort, Is.ConnectedTo(set.InstancePort)); Assert.That(v2.OutputPort, Is.ConnectedTo(set.ValuePort)); return(new ChangeStackedNodeAction(set, stackModel, item)); }, () => { Assert.That(stackModel.NodeModels.Count, Is.EqualTo(1)); Assert.That(stackModel.NodeModels.Single(), Is.TypeOf <LogNodeModel>()); var log = stackModel.NodeModels.OfType <LogNodeModel>().Single(); Assert.That(v1.OutputPort, Is.ConnectedTo(log.InputPort)); Assert.That(v2.OutputPort.Connected, Is.False); }); }
public IEnumerator Test_DuplicateCommandSkipsSingleInstanceModels() { GraphModel.CreateStack("stack", new Vector2(200, 50)); Vector2 position = new Vector2(200, 150); GraphModel.CreateNode <UniqueInstanceFunctionModel>("Start", position); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.That(GetGraphElements().Count, Is.EqualTo(2)); Helpers.MouseClickEvent(GetGraphElement(0).GetGlobalCenter()); // Ensure we have focus yield return(null); GraphView.selection.Add(GetGraphElement(0)); GraphView.selection.Add(GetGraphElement(1)); Helpers.ExecuteCommand("Duplicate"); yield return(null); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.That(GetGraphElements().Count, Is.EqualTo(3), "Duplicate should have skipped the Start event function node"); }
public void NestedIfs() { var a = GraphModel.CreateFunction("A", Vector2.zero); StackBaseModel b, c; CreateIfThenElseStacks(a, "b", "c", out b, out c); var d = GraphModel.CreateStack("d", Vector2.left); var e = GraphModel.CreateStack("e", Vector2.left); b.CreateStackedNode <Type0FakeNodeModel>("b"); c.CreateStackedNode <Type0FakeNodeModel>("c"); d.CreateStackedNode <Type0FakeNodeModel>("d"); e.CreateStackedNode <Type0FakeNodeModel>("e"); var cIfNode = c.CreateStackedNode <IfConditionNodeModel>("if_c"); GraphModel.CreateEdge(b.InputPorts[0], cIfNode.ThenPort); GraphModel.CreateEdge(d.InputPorts[0], cIfNode.ElsePort); GraphModel.CreateEdge(e.InputPorts[0], b.OutputPorts[0]); GraphModel.CreateEdge(e.InputPorts[0], d.OutputPorts[0]); // as C has an if node, a common descendant of (C,X) must be a descendant of (B,D,X), here E Assert.That(RoslynTranslator.FindCommonDescendant(a, a, c), Is.EqualTo(e)); Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(e)); }
public void Test_CreateStackedNodesFromSearcherAction(TestingMode mode, Type expectedNodeType, Type[] expectedStackTypes, Func <Stencil, StackBaseModel, StackNodeModelSearcherItem> makeItemFunc) { var stack = GraphModel.CreateStack("stack", Vector2.zero); var item = makeItemFunc(Stencil, stack); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetStackCount(), Is.EqualTo(1)); Assert.That(stack.NodeModels.Count, Is.EqualTo(0)); return(new CreateStackedNodeFromSearcherAction(stack, -1, item)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(1 + expectedStackTypes.Length)); Assert.That(GetStackCount(), Is.EqualTo(1 + expectedStackTypes.Length)); Assert.That(stack.NodeModels.Count, Is.EqualTo(1)); var stackedNodes = stack.NodeModels.ToList(); Assert.That(stackedNodes[0].GetType(), Is.EqualTo(expectedNodeType)); int cnt = 1; foreach (var expectedStackType in expectedStackTypes) { var newStack = GetStack(cnt++); Assert.That(newStack.GetType(), Is.EqualTo(expectedStackType)); } } ); }
public IEnumerator RefreshUIPreservesSelection() { var stackModel0 = GraphModel.CreateStack("A", new Vector2(100, -100)); var stackModel1 = GraphModel.CreateStack("B", new Vector2(100, 100)); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); GraphView.ClearSelection(); GraphView.AddToSelection(GraphView.UIController.ModelsToNodeMapping[stackModel0]); yield return(SendPanToNodeAndRefresh(stackModel0)); GraphView.ClearSelection(); GraphView.AddToSelection(GraphView.UIController.ModelsToNodeMapping[stackModel1]); yield return(SendPanToNodeAndRefresh(stackModel1)); IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel) { Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.That(GraphView.selection. OfType <IHasGraphElementModel>(). Where(x => x.GraphElementModel is INodeModel n && n.Guid == nodeModel.Guid).Any, () => { var graphViewSelection = String.Join(",", GraphView.selection.Select(x => x is IHasGraphElementModel hasModel ? hasModel.GraphElementModel.ToString() : x.ToString())); return($"Selection doesn't contain {nodeModel} {nodeModel.Title} but {graphViewSelection}"); }); } }
public void Test_CreateNodeFromExecutionPort_FromOutput(TestingMode testingMode) { var stack = GraphModel.CreateStack("Stack", Vector2.zero); TestPrereqActionPostreq(testingMode, () => { RefreshReference(ref stack); var output0 = stack.OutputPorts[0]; Assert.That(GetStackCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); return(new CreateNodeFromExecutionPortAction(output0, Vector2.down)); }, () => { RefreshReference(ref stack); Assert.That(GetStackCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); var newStack = GetStack(1); Assert.That(newStack, Is.TypeOf <StackModel>()); Assert.That(stack.OutputPorts[0].ConnectionPortModels.First(), Is.EqualTo(newStack.InputPorts[0])); }); }
public IEnumerator Test_AddNodeAtEndOfBranchTypeStackPutsItBeforeCondition() { var offset = new Vector2(300, 0); var stackModel = GraphModel.CreateStack(string.Empty, offset); stackModel.CreateStackedNode <Type0FakeNodeModel>("Node0"); stackModel.CreateStackedNode <IfConditionNodeModel>("IfCondition", 0); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); var stack = GetGraphElement(0); Assert.That(stack.Children().OfType <Node>().LastOrDefault() is IfConditionNode); // Position mouse above last stack separator (below IfCondition node) Vector2 position = new Vector2(offset.x + stack.layout.width / 2 - 15, offset.y + stack.layout.height - 6); Vector2 worldPosition = GraphView.contentViewContainer.LocalToWorld(position); Helpers.MouseMoveEvent(Vector2.zero, worldPosition); yield return(null); // Even though mouse position corresponds to insertion index == 2, make sure that // the actual index is 1 (above IfCondition node) var insertionIndex = ((StackNode)stack).GetInsertionIndex(position); Assert.That(insertionIndex, Is.EqualTo(1)); }
public void Test_CreateStackedNodeFromOutputPort_NoNodeCreated([Values] TestingMode mode) { var stack1 = GraphModel.CreateStack("Stack1", Vector2.zero); var stack2 = GraphModel.CreateStack("Stack2", Vector2.zero); var edge = GraphModel.CreateEdge(stack1.InputPorts[0], stack2.OutputPorts[0]); TestPrereqActionPostreq(mode, () => { Assert.That(GetEdgeCount(), Is.EqualTo(1)); return(new CreateStackedNodeFromOutputPortAction( stack1.OutputPorts[0], stack1, 0, new StackNodeModelSearcherItem( new NodeSearcherItemData(typeof(int)), data => Enumerable.Empty <IGraphElementModel>().ToArray(), ""), new List <IEdgeModel> { edge })); }, () => { Assert.That(GetEdgeCount(), Is.EqualTo(0)); }); }
public void Test_CreateInsertLoopNode([Values] TestingMode mode) { GraphModel.CreateStack(string.Empty, Vector2.zero); GraphModel.CreateLoopStack <ForEachHeaderModel>(Vector2.right * 100); TestPrereqActionPostreq(mode, () => { var loopStack = GetStack(1) as LoopStackModel; var stack = GetStack(0); Assert.That(stack.NodeModels.Count, Is.EqualTo(0)); var portModel = loopStack.InputPort; Assert.That(portModel.Connected, Is.False); return(new CreateInsertLoopNodeAction( loopStack.InputPorts.First(), stack, -1, (LoopStackModel)portModel.NodeModel)); }, () => { var loopStack = GetStack(1) as LoopStackModel; var stack = GetStack(0); Assert.That(stack.NodeModels.Count, Is.EqualTo(1)); var loopNode = stack.NodeModels.First() as ForEachNodeModel; Assert.That(loopNode, Is.Not.Null); Assert.NotNull(loopNode); var portModel = loopNode.OutputPort; Assert.That(portModel.Connected, Is.True); Assert.That(portModel.ConnectionPortModels.Single(), Is.EqualTo(loopStack.InputPort)); }); }
public void DuplicateStackedNode([Values] TestingMode mode) { var stack = GraphModel.CreateStack("stack", Vector2.zero); stack.CreateStackedNode <Type0FakeNodeModel>("test"); TestPrereqActionPostreq(mode, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(1)); }, () => { var node = stack.NodeModels.Single(); TargetInsertionInfo info; info.OperationName = "Duplicate"; info.Delta = Vector2.one; info.TargetStack = stack; info.TargetStackInsertionIndex = -1; IEditorDataModel editorDataModel = m_Store.GetState().EditorDataModel; VseGraphView.CopyPasteData copyPasteData = VseGraphView.GatherCopiedElementsData(VseGraphView.CopyMode.KeepReference, new List <IGraphElementModel> { node }); Assert.That(copyPasteData.IsEmpty(), Is.False); return(new PasteSerializedDataAction(GraphModel, info, editorDataModel, copyPasteData.ToJson())); }, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(2)); }); }
public void Test_CreateNodeFromExecutionPort_FromOutput(TestingMode testingMode, GroupingMode groupingMode) { var inGroupTest = groupingMode == GroupingMode.Grouped; var stack = GraphModel.CreateStack("Stack", Vector2.zero); var output0 = stack.OutputPorts[0]; var group = inGroupTest ? GraphModel.CreateGroupNode(string.Empty, Vector2.zero) : null; TestPrereqActionPostreq(testingMode, () => { Assert.That(GetStackCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); return(new CreateNodeFromExecutionPortAction(output0, Vector2.down, groupModel: group)); }, () => { Assert.That(GetStackCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); var newStack = GetStack(1); Assert.That(newStack, Is.TypeOf <StackModel>()); Assert.That(newStack.IsGrouped, Is.EqualTo(inGroupTest)); Assert.That(newStack.GroupNodeModel, Is.EqualTo(group)); Assert.That(stack.OutputPorts[0].ConnectionPortModels.First(), Is.EqualTo(newStack.InputPorts[0])); }); }
public IEnumerator EndToEndMoveDependencyWithPanning() { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(100, -100)); var stackModel1 = GraphModel.CreateStack(string.Empty, new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); GraphView.FrameAll(); yield return(null); bool needsMouseUp = false; try { using (var scheduler = GraphView.CreateTimerEventSchedulerWrapper()) { GraphElement stackNode = GraphView.UIController.ModelsToNodeMapping[stackModel0]; Vector2 startPos = stackNode.GetPosition().position; Vector2 otherStartPos = stackModel1.Position; Vector2 nodeRect = stackNode.hierarchy.parent.ChangeCoordinatesTo(Window.rootVisualElement, stackNode.layout.center); // Move the movable node. Vector2 pos = nodeRect; Vector2 target = new Vector2(Window.rootVisualElement.layout.xMax - 20, pos.y); needsMouseUp = true; bool changed = false; GraphView.viewTransformChanged += view => changed = true; Helpers.MouseDownEvent(pos); yield return(null); Helpers.MouseMoveEvent(pos, target); Helpers.MouseDragEvent(pos, target); yield return(null); scheduler.TimeSinceStartup += GraphViewTestHelpers.SelectionDraggerPanInterval; scheduler.UpdateScheduledEvents(); Helpers.MouseUpEvent(target); needsMouseUp = false; Assume.That(changed, Is.True); yield return(null); Vector2 delta = stackNode.GetPosition().position - startPos; Assert.That(stackModel1.Position, Is.EqualTo(otherStartPos + delta)); } } finally { if (needsMouseUp) { Helpers.MouseUpEvent(Vector2.zero); } } }
void CreateIfThenElseStacks(StackBaseModel ifStack, string thenName, string elseName, out StackBaseModel thenStack, out StackBaseModel elseStack) { var ifNode = ifStack.CreateStackedNode <IfConditionNodeModel>("if"); thenStack = GraphModel.CreateStack(thenName, Vector2.left); GraphModel.CreateEdge(thenStack.InputPorts[0], ifNode.ThenPort); elseStack = GraphModel.CreateStack(elseName, Vector2.right); GraphModel.CreateEdge(elseStack.InputPorts[0], ifNode.ElsePort); }
public void TestCreateEdge_CannotConnectForEachNodeToWhileStack() { var stack = GraphModel.CreateStack("", Vector2.zero); var forEach = stack.CreateStackedNode <ForEachNodeModel>(); var whileStack = GraphModel.CreateLoopStack <WhileHeaderModel>(Vector2.zero); var edgeCount = GetEdgeCount(); m_Store.Dispatch(new CreateEdgeAction(whileStack.InputPort, forEach.OutputPort)); Assert.That(GetEdgeCount(), Is.EqualTo(edgeCount)); }
IfConditionNodeModel CreateIfThenElseStacks(StackBaseModel ifStack, out StackBaseModel thenStack, out StackBaseModel elseStack) { var ifNode = ifStack.CreateStackedNode <IfConditionNodeModel>("if"); thenStack = GraphModel.CreateStack("then", Vector2.left); GraphModel.CreateEdge(thenStack.InputPorts[0], ifNode.ThenPort); elseStack = GraphModel.CreateStack("else", Vector2.right); GraphModel.CreateEdge(elseStack.InputPorts[0], ifNode.ElsePort); return(ifNode); }
public IEnumerator MovingAStackMovesTheConnectedStack([Values] TestingMode mode) { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100)); var stackModel1 = GraphModel.CreateStack(string.Empty, new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); yield return(TestMove(mode, mouseDelta: new Vector2(20, 10), movedNodes: new INodeModel[] { stackModel0 }, expectedMovedDependencies: new INodeModel[] { stackModel1 } )); }
public IEnumerator Test_CreateStackWithNodes() { var stackModel = GraphModel.CreateStack(string.Empty, Vector2.zero); stackModel.CreateStackedNode <Type0FakeNodeModel>("Node0"); stackModel.CreateStackedNode <Type1FakeNodeModel>("Node1"); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.That(GetGraphElements().Count, Is.EqualTo(3)); Assert.That(GetGraphElement(0).Children().OfType <Node>().Count(), Is.EqualTo(2)); yield return(null); }
public IEnumerator Test_CreateEdgeBetweenStack() { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100)); var stackModel1 = GraphModel.CreateStack(string.Empty, new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.That(GetGraphElements().Count, Is.EqualTo(3)); Assert.That(GraphView.edges.ToList().Count, Is.EqualTo(1)); yield return(null); }
public void Test_Translate_DetectInfiniteLoop() { var function = GraphModel.CreateFunction("Function", Vector2.zero); var stack0 = GraphModel.CreateStack(string.Empty, Vector2.zero); var stack1 = GraphModel.CreateStack(string.Empty, Vector2.zero); GraphModel.CreateEdge(stack0.InputPorts[0], function.OutputPort); GraphModel.CreateEdge(stack0.InputPorts[0], stack1.OutputPorts[0]); GraphModel.CreateEdge(stack1.InputPorts[0], stack0.OutputPorts[0]); var b = new RoslynTranslator(Stencil); Assert.Throws <LoopDetectedException>(() => b.Translate(GraphModel, CompilationOptions.Default)); }
public IEnumerator MovingAStackMovesTheConnectedLoopStack([Values] TestingMode mode) { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100)); var loopStack = GraphModel.CreateLoopStack <WhileHeaderModel>(new Vector2(50, 50)); var whileModel = loopStack.CreateLoopNode(stackModel0, 0); GraphModel.CreateEdge(loopStack.InputPort, whileModel.OutputPort); yield return(TestMove(mode, mouseDelta: new Vector2(20, 10), movedNodes: new INodeModel[] { stackModel0 }, expectedMovedDependencies: new INodeModel[] { loopStack } )); }
public void Test_MoveIfToNewStackPreservesConnections([Values] TestingMode mode) { { var ifStack = GraphModel.CreateStack("stack1", Vector2.up); var thenStack = GraphModel.CreateStack("thenStack", Vector2.left); var elseStack = GraphModel.CreateStack("elseStack", Vector2.right); var logNode = ifStack.CreateStackedNode <LogNodeModel>("log"); var ifNode = ifStack.CreateStackedNode <IfConditionNodeModel>("if"); GraphModel.CreateEdge(thenStack.InputPorts[0], ifNode.ThenPort); GraphModel.CreateEdge(elseStack.InputPorts[0], ifNode.ElsePort); } TestPrereqActionPostreq(mode, () => { Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(GetStackCount(), Is.EqualTo(3)); var ifStack = GetStack(0); var thenStack = GetStack(1); var elseStack = GetStack(2); var logNode = ifStack.NodeModels[0]; var ifStackNode = ifStack.NodeModels[1]; Assert.That(ifStackNode, NUnit.Framework.Is.TypeOf <IfConditionNodeModel>()); var ifNode = (IfConditionNodeModel)ifStackNode; Assert.That(ifStack.OutputPorts[0], Is.ConnectedTo(thenStack.InputPorts[0])); Assert.That(ifStack.OutputPorts[1], Is.ConnectedTo(elseStack.InputPorts[0])); Assert.That(ifNode.ThenPort, Is.ConnectedTo(thenStack.InputPorts[0])); Assert.That(ifNode.ElsePort, Is.ConnectedTo(elseStack.InputPorts[0])); return(new CreateStacksForNodesAction(new List <StackCreationOptions> { new StackCreationOptions(Vector2.zero, new List <INodeModel> { ifNode }) })); }, () => { Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(GetStackCount(), Is.EqualTo(4)); var oldStack = GetStack(0); var thenStack = GetStack(1); var elseStack = GetStack(2); var newStack = GetStack(3); var logNode = oldStack.NodeModels[0]; var ifStackNode = newStack.NodeModels[0]; Assert.That(ifStackNode, Is.TypeOf <IfConditionNodeModel>()); var ifNode = (IfConditionNodeModel)ifStackNode; Assert.That(ifNode.ThenPort, Is.ConnectedTo(thenStack.InputPorts[0])); Assert.That(ifNode.ElsePort, Is.ConnectedTo(elseStack.InputPorts[0])); }); }
public void Test_DeleteStackAction_OneEmptyStack([Values] TestingMode mode) { GraphModel.CreateStack(string.Empty, Vector2.zero); TestPrereqActionPostreq(mode, () => { Assert.That(GetStackCount(), Is.EqualTo(1)); return(new DeleteElementsAction(GetFloatingStack(0))); }, () => { Assert.That(GetStackCount(), Is.EqualTo(0)); }); }
public IEnumerator MovingAStackMovesStackedNodeConnectedFloatingNode([Values] TestingMode mode) { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100)); UnaryOperatorNodeModel unary = stackModel0.CreateStackedNode <UnaryOperatorNodeModel>("postDecr", setup: n => n.kind = UnaryOperatorKind.PostDecrement); BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); IConstantNodeModel intModel = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100)); GraphModel.CreateEdge(unary.InputPort, operatorModel.OutputPort); GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort); yield return(TestMove(mode, mouseDelta: new Vector2(20, 10), movedNodes: new INodeModel[] { stackModel0 }, expectedMovedDependencies: new INodeModel[] { operatorModel, intModel } )); }
public void Test_SplitStackAction([Values] TestingMode mode) { GraphModel.CreateStack("stack0", Vector2.zero); GraphModel.CreateStack("stack1", Vector2.zero); GraphModel.CreateStack("stack2", Vector2.zero); var stack0 = GetStack(0); var stack1 = GetStack(1); var stack2 = GetStack(2); var nodeA = stack1.CreateStackedNode <Type0FakeNodeModel>("A"); var nodeB = stack1.CreateStackedNode <Type0FakeNodeModel>("B"); var nodeC = stack1.CreateStackedNode <Type0FakeNodeModel>("C"); GraphModel.CreateEdge(stack1.InputPorts[0], stack0.OutputPorts.First()); GraphModel.CreateEdge(stack2.InputPorts[0], stack1.OutputPorts.First()); TestPrereqActionPostreq(mode, () => { Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(GetStackCount(), Is.EqualTo(3)); Assert.That(stack0, Is.ConnectedToStack(stack1)); Assert.That(stack1, Is.ConnectedToStack(stack2)); Assert.That(nodeA, Is.InsideStack(stack1)); Assert.That(nodeB, Is.InsideStack(stack1)); Assert.That(nodeC, Is.InsideStack(stack1)); Assert.That(stack0.NodeModels.Count, Is.EqualTo(0)); Assert.That(stack1.NodeModels.Count, Is.EqualTo(3)); Assert.That(stack2.NodeModels.Count, Is.EqualTo(0)); return(new SplitStackAction(stack1, 1)); }, () => { var stack3 = GetStack(3); Assert.That(GetEdgeCount(), Is.EqualTo(3)); Assert.That(GetStackCount(), Is.EqualTo(4)); Assert.That(stack0, Is.ConnectedToStack(stack1)); Assert.That(stack1, Is.ConnectedToStack(stack3)); Assert.That(stack3, Is.ConnectedToStack(stack2)); Assert.That(nodeA, Is.InsideStack(stack1)); Assert.That(nodeB, Is.InsideStack(stack3)); Assert.That(nodeC, Is.InsideStack(stack3)); Assert.That(stack0.NodeModels.Count, Is.EqualTo(0)); Assert.That(stack1.NodeModels.Count, Is.EqualTo(1)); Assert.That(stack2.NodeModels.Count, Is.EqualTo(0)); Assert.That(stack3.NodeModels.Count, Is.EqualTo(2)); }); }
public IEnumerator PanToNodeChangesViewTransform() { BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); var stackModel0 = GraphModel.CreateStack("Stack 1", new Vector2(100, -100)); var stackModel1 = GraphModel.CreateStack("Stack 2", new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); var nodeA = stackModel0.CreateStackedNode <Type0FakeNodeModel>("A"); var nodeB = stackModel0.CreateStackedNode <Type0FakeNodeModel>("B"); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); GraphView.viewTransformChanged += view => m_Changed = true; yield return(SendPanToNodeAndRefresh(stackModel0)); yield return(SendPanToNodeAndRefresh(stackModel1)); yield return(SendPanToNodeAndRefresh(operatorModel)); yield return(SendPanToNodeAndRefresh(nodeA)); yield return(SendPanToNodeAndRefresh(nodeB)); IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel) { m_Changed = false; Store.Dispatch(new PanToNodeAction(nodeModel.Guid)); yield return(null); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.IsTrue(m_Changed, "ViewTransform didn't change"); Assert.That(GraphView.selection. OfType <IHasGraphElementModel>(). Where(x => x.GraphElementModel is INodeModel n && n.Guid == nodeModel.Guid).Any, () => { var graphViewSelection = String.Join(",", GraphView.selection); return($"Selection doesn't contain {nodeModel} {nodeModel.Title} but {graphViewSelection}"); }); } }
public void Test_MoveStackedNodeAction_ToSameStack([Values] TestingMode mode) { var stack = GraphModel.CreateStack(string.Empty, Vector2.zero); var nodeA = stack.CreateStackedNode <Type0FakeNodeModel>("A"); var nodeB = stack.CreateStackedNode <Type0FakeNodeModel>("B"); var nodeC = stack.CreateStackedNode <Type0FakeNodeModel>("C"); var nodeD = stack.CreateStackedNode <Type0FakeNodeModel>("D"); TestPrereqActionPostreq(mode, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(4)); Assert.That(nodeA, Has.IndexInStack(0, stack)); Assert.That(nodeB, Has.IndexInStack(1, stack)); Assert.That(nodeC, Has.IndexInStack(2, stack)); Assert.That(nodeD, Has.IndexInStack(3, stack)); return(new MoveStackedNodesAction(new[] { nodeA }, stack, 2)); }, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(4)); Assert.That(nodeB, Has.IndexInStack(0, stack)); Assert.That(nodeC, Has.IndexInStack(1, stack)); Assert.That(nodeA, Has.IndexInStack(2, stack)); Assert.That(nodeD, Has.IndexInStack(3, stack)); }); TestPrereqActionPostreq(mode, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(4)); Assert.That(nodeB, Has.IndexInStack(0, stack)); Assert.That(nodeC, Has.IndexInStack(1, stack)); Assert.That(nodeA, Has.IndexInStack(2, stack)); Assert.That(nodeD, Has.IndexInStack(3, stack)); return(new MoveStackedNodesAction(new[] { nodeD }, stack, 0)); }, () => { Assert.That(stack.NodeModels.Count, Is.EqualTo(4)); Assert.That(nodeD, Has.IndexInStack(0, stack)); Assert.That(nodeB, Has.IndexInStack(1, stack)); Assert.That(nodeC, Has.IndexInStack(2, stack)); Assert.That(nodeA, Has.IndexInStack(3, stack)); }); }
void CreateNodesAndValidateStackModel(StackNodeModelSearcherItem item, SpawnFlags mode, Action <List <INodeModel>, IStackModel> assertNodesCreation) { var stack = GraphModel.CreateStack("stack", Vector2.zero); var initialGraphNodes = GraphModel.NodeModels.ToList(); item.CreateElements.Invoke(new StackNodeCreationData(stack, -1, spawnFlags: mode)); // If nodes are created as Orphan, graphModel and stackModel should not be modified if (mode.IsOrphan()) { Assert.AreEqual(stack.NodeModels.Count(), 0); CollectionAssert.AreEqual(initialGraphNodes, GraphModel.NodeModels); return; } assertNodesCreation.Invoke(initialGraphNodes, stack); }