public void OneGroupIterationSystem_SharedAndRegularComponents([Values(CodeGenMode.NoJobs)] CodeGenMode mode) { SetupTestGraph(mode, g => { var query = GraphModel.CreateComponentQuery("query"); var positionType = typeof(Translation).GenerateTypeHandle(Stencil); query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None); var renderType = typeof(RenderMesh).GenerateTypeHandle(Stencil); query.AddComponent(Stencil, renderType, ComponentDefinitionFlags.Shared); var queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero); var onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero); GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort); var posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero); var renderComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == renderType), Vector2.zero); var logTranslation = onUpdateModel.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0); var logRenderMesh = onUpdateModel.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 1); GraphModel.CreateEdge(logTranslation.GetParameterPorts().First(), posComponent.OutputPort); GraphModel.CreateEdge(logRenderMesh.GetParameterPorts().First(), renderComponent.OutputPort); }, (manager, entityIndex, e) => { manager.AddComponentData(e, new Translation { Value = { x = entityIndex } }); manager.AddSharedComponentData(e, new RenderMesh()); }, (manager, entityIndex, e) => Assert.Pass()); }
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 void ExtractTwoNodesConnectedToTheSameNodeDifferentPorts([Values] TestingMode mode) { var stack = GraphModel.CreateFunction("F", Vector2.zero); var set = stack.CreateStackedNode <SetVariableNodeModel>("set"); var varA = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero); var varB = GraphModel.CreateVariableNode(m_BDecl, Vector2.zero); GraphModel.CreateEdge(set.InstancePort, varA.OutputPort); GraphModel.CreateEdge(set.ValuePort, varB.OutputPort); Undo.IncrementCurrentGroup(); TestPrereqActionPostreq(mode, () => { set = stack.NodeModels.OfType <SetVariableNodeModel>().Single(); Assert.That(GraphModel.NodeModels.OfType <MacroRefNodeModel>().Count(), Is.Zero); Assert.That(set.InstancePort, Is.ConnectedTo(varA.OutputPort)); Assert.That(set.ValuePort, Is.ConnectedTo(varB.OutputPort)); return(new RefactorExtractMacroAction(new List <IGraphElementModel> { varA, varB }, Vector2.zero, null)); }, () => { var macroRef = GraphModel.NodeModels.OfType <MacroRefNodeModel>().Single(); Assert.That(macroRef, Is.Not.Null); var macroRefOutputPorts = macroRef.OutputVariablePorts.ToList(); Assert.That(macroRefOutputPorts.Count, Is.EqualTo(2)); Assert.That(macroRefOutputPorts[0], Is.ConnectedTo(set.InstancePort)); Assert.That(macroRefOutputPorts[1], Is.ConnectedTo(set.ValuePort)); Assert.That(macroRef.Macro.Stencil, Is.TypeOf <MacroStencil>()); Assert.That(((MacroStencil)macroRef.Macro.Stencil).ParentType, Is.EqualTo(GraphModel.Stencil.GetType())); }); }
public void SendEventNestedTest([Values] CodeGenMode mode) { SetupTestGraphMultipleFrames(mode, graphModel => { // group1 - Position var group1 = graphModel.CreateComponentQuery("g1"); group1.AddComponent(graphModel.Stencil, typeof(Translation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None); var group1Instance = graphModel.CreateVariableNode(group1, Vector2.zero); // group2 - Scale (will add RenderMesh) var group2 = graphModel.CreateComponentQuery("g2"); group2.AddComponent(graphModel.Stencil, typeof(Scale).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None); var group2Instance = graphModel.CreateVariableNode(group2, Vector2.zero); // update group 1 var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero); graphModel.CreateEdge(onUpdateEntities.InstancePort, group1Instance.OutputPort); // nested update group 2 var forAllStack = GraphModel.CreateLoopStack <ForAllEntitiesStackModel>(Vector2.zero); var forAllNode = forAllStack.CreateLoopNode(onUpdateEntities, 0) as ForAllEntitiesNodeModel; graphModel.CreateEdge(forAllNode.InputPort, group2Instance.OutputPort); graphModel.CreateEdge(forAllStack.InputPort, forAllNode.OutputPort); TypeHandle eventTypeHandle = typeof(UnitTestEvent).GenerateTypeHandle(Stencil); SendEventNodeModel set = forAllStack.CreateStackedNode <SendEventNodeModel>("set", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle); TypeHandle entityType = typeof(Entity).GenerateTypeHandle(Stencil); IVariableModel entityVar = GraphModel.CreateVariableNode(forAllStack.FunctionParameterModels.Single(p => p.DataType == entityType), Vector2.zero); var firstFieldInput = set.EntityPort; GraphModel.CreateEdge(firstFieldInput, entityVar.OutputPort); } ); }
public IEnumerator DuplicateNodeAndEdgeCreatesEdgeToOriginalNode() { var declaration0 = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), "decl0", ModifierFlags.None, true); var nodeA = GraphModel.CreateVariableNode(declaration0, new Vector2(100, -100)); var nodeB = GraphModel.CreateNode <Type0FakeNodeModel>("A", new Vector2(100, 100)); var edge = GraphModel.CreateEdge(nodeB.Input0, nodeA.OutputPort) as EdgeModel; MarkGraphViewStateDirty(); yield return(null); CommandDispatcher.Dispatch(new SelectElementsCommand(SelectElementsCommand.SelectionMode.Replace, new GraphElementModel[] { nodeB, edge })); GraphView.Focus(); using (var evt = ExecuteCommandEvent.GetPooled("Duplicate")) { evt.target = GraphView; GraphView.SendEvent(evt); } yield return(null); Assert.AreEqual(3, GraphModel.NodeModels.Count); Assert.AreEqual(2, GraphModel.EdgeModels.Count); foreach (var edgeModel in GraphModel.EdgeModels) { Assert.AreEqual(nodeA.OutputPort, edgeModel.FromPort); } }
public void ShufflingPortsPreserveConnections() { var node = GraphModel.CreateNode <PortOrderTestNodeModel>("test", Vector2.zero); node.MakePortsFromNames(new List <string> { "A", "B", "C" }); node.DefineNode(); var decl = GraphModel.CreateGraphVariableDeclaration("myInt", TypeHandle.Int, true); var nodeA = GraphModel.CreateVariableNode(decl, Vector2.up); var nodeB = GraphModel.CreateVariableNode(decl, Vector2.zero); var nodeC = GraphModel.CreateVariableNode(decl, Vector2.down); GraphModel.CreateEdge(node.InputsById["A"], nodeA.OutputPort); GraphModel.CreateEdge(node.InputsById["B"], nodeB.OutputPort); GraphModel.CreateEdge(node.InputsById["C"], nodeC.OutputPort); Assert.That(nodeA.OutputPort, Is.ConnectedTo(node.InputsById["A"])); Assert.That(nodeB.OutputPort, Is.ConnectedTo(node.InputsById["B"])); Assert.That(nodeC.OutputPort, Is.ConnectedTo(node.InputsById["C"])); Assert.That(node.IsSorted, Is.True); node.RandomizePorts(); Assert.That(node.IsSorted, Is.False); node.DefineNode(); Assert.That(nodeA.OutputPort, Is.ConnectedTo(node.InputsById["A"])); Assert.That(nodeB.OutputPort, Is.ConnectedTo(node.InputsById["B"])); Assert.That(nodeC.OutputPort, Is.ConnectedTo(node.InputsById["C"])); }
public void ExtractLinkedThreeNodesWithOneSharedInput() { // a > b && a < c FunctionCallNodeModel[] log; CreateStackAndLogs(out _, out log); var greater = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.GreaterThan, Vector2.zero); var lower = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.LessThan, Vector2.zero); var and = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.LogicalAnd, Vector2.zero); var varA = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero); var varB = GraphModel.CreateVariableNode(m_BDecl, Vector2.zero); var varC = GraphModel.CreateVariableNode(m_CDecl, Vector2.zero); List <IGraphElementModel> extract = new List <IGraphElementModel> { greater, lower, and, }; GraphModel.CreateEdge(log[0].GetParameterPorts().First(), and.OutputPort); extract.Add(GraphModel.CreateEdge(and.InputPortA, greater.OutputPort)); extract.Add(GraphModel.CreateEdge(and.InputPortB, lower.OutputPort)); GraphModel.CreateEdge(greater.InputPortA, varA.OutputPort); GraphModel.CreateEdge(greater.InputPortB, varB.OutputPort); GraphModel.CreateEdge(lower.InputPortA, varA.OutputPort); GraphModel.CreateEdge(lower.InputPortB, varC.OutputPort); TestExtractMacro(extract, new IO(varA.OutputPort, varB.OutputPort, varC.OutputPort), new IO(log[0].GetParameterPorts().First())); }
public void MacroPortsRemainConnectedAfterMacroAssetDeletion() { FunctionCallNodeModel[] log; CreateStackAndLogs(out _, out log); var binOp = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); var varA = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero); GraphModel.CreateEdge(log[0].GetParameterPorts().First(), binOp.OutputPort); GraphModel.CreateEdge(binOp.InputPortA, varA.OutputPort); GraphModel.CreateEdge(binOp.InputPortB, varA.OutputPort); TestPrereqActionPostreq(TestingMode.Action, () => { binOp = GraphModel.NodeModels.OfType <BinaryOperatorNodeModel>().Single(); Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3)); Assert.That(GraphModel.NodeModels.OfType <MacroRefNodeModel>().Count(), Is.Zero); Assert.That(binOp.InputPortA, Is.ConnectedTo(varA.OutputPort)); Assert.That(binOp.InputPortB, Is.ConnectedTo(varA.OutputPort)); Assert.That(binOp.OutputPort, Is.ConnectedTo(log[0].GetParameterPorts().First())); return(new RefactorExtractMacroAction(new List <IGraphElementModel> { binOp }, Vector2.zero, null)); }, () => { Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(3)); var macroRef = GraphModel.NodeModels.OfType <MacroRefNodeModel>().Single(); macroRef.GraphAssetModel = null; macroRef.DefineNode(); Assert.That(macroRef, Is.Not.Null); Assert.That(macroRef.InputVariablePorts.First(), Is.ConnectedTo(varA.OutputPort)); Assert.That(macroRef.OutputVariablePorts.First(), Is.ConnectedTo(log[0].GetParameterPorts().First())); }); }
[Test] // TODO: fix jobs public void OnEnterWorks([Values(CodeGenMode.NoJobs)] CodeGenMode mode) { SetupTestGraphMultipleFrames(mode, graphModel => { var group = graphModel.CreateComponentQuery("g"); var positionType = typeof(Translation).GenerateTypeHandle(Stencil); group.AddComponent(graphModel.Stencil, positionType, ComponentDefinitionFlags.None); group.AddComponent(graphModel.Stencil, typeof(Rotation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None); var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero); var update = graphModel.CreateNode <OnStartEntitiesNodeModel>("update", Vector2.zero); graphModel.CreateEdge(update.InstancePort, groupInstance.OutputPort); var set = update.CreateStackedNode <SetPositionNodeModel>("set", 0, SpawnFlags.Default, n => n.Mode = SetPositionNodeModel.TranslationMode.Float3); set.Add = true; // increment so we can detect multiple runs if they happen ((Float3ConstantModel)set.InputConstantsById["Value"]).value = new Vector3(1f, 0.0f, 0.0f); IVariableModel posComponent = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero); GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort); }, EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Rotation))), EachEntity((manager, i, e) => { manager.AddComponent(e, typeof(Translation)); // will make the entity enter the query Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(0)); }), EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1))), // translate ran once EachEntity((manager, i, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(1))) // not twice ); }
public void Test_ConvertVariableNodeToConstantNodeAction([Values] TestingMode mode) { var declaration0 = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true); var node0 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); var node1 = GraphModel.CreateVariableNode(declaration0, Vector2.zero); IPortModel outputPort = node1.OutputPort; GraphModel.CreateEdge(node0.InputPortA, outputPort); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(GetNode(1), Is.TypeOf <VariableNodeModel>()); var n0 = (BinaryOperatorNodeModel)GetNode(0); var n1 = (VariableNodeModel)GetNode(1); Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort)); return(new ConvertVariableNodesToConstantNodesAction(node1)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(GetNode(1), Is.TypeOf <IntConstantModel>()); var n0 = (BinaryOperatorNodeModel)GetNode(0); var n1 = (IntConstantModel)GetNode(1); Assert.That(n0.InputPortA, Is.ConnectedTo(n1.OutputPort)); }); }
public void OneGroupIterationSystem([Values] CodeGenMode mode) { SetupTestGraph(mode, g => { ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1"); TypeHandle positionType = typeof(Translation).GenerateTypeHandle(Stencil); query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None); IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero); OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero); GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort); SetPropertyGroupNodeModel set = onUpdateModel.CreateStackedNode <SetPropertyGroupNodeModel>("set"); var member = new TypeMember(TypeHandle.Float, new List <string> { nameof(Translation.Value), nameof(Translation.Value.x) }); set.AddMember(member); IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == positionType), Vector2.zero); GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort); ((FloatConstantModel)set.InputConstantsById[member.GetId()]).value = 2f; }, (manager, entityIndex, e) => manager.AddComponentData(e, new Translation { Value = { x = entityIndex } }), (manager, entityIndex, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f))); }
public IEnumerator ConvertVariableNodesToConstantNodesCommandWorks([Values] TestingMode mode) { var vdm = GraphModel.CreateGraphVariableDeclaration(TypeHandle.Float, "blah", ModifierFlags.ReadOnly, false); var variable = GraphModel.CreateVariableNode(vdm, Vector2.zero); yield return(TestPrereqCommandPostreq(mode, () => { Assert.AreEqual(0, GraphModel.NodeModels.Count(n => n is IConstantNodeModel)); Assert.AreEqual(1, GraphModel.NodeModels.Count(n => n is IVariableNodeModel)); }, frame => { switch (frame) { case 0: CommandDispatcher.Dispatch(new ConvertConstantNodesAndVariableNodesCommand(null, new[] { variable })); return TestPhase.WaitForNextFrame; default: return TestPhase.Done; } }, () => { Assert.AreEqual(1, GraphModel.NodeModels.Count(n => n is IConstantNodeModel)); Assert.AreEqual(0, GraphModel.NodeModels.Count(n => n is IVariableNodeModel)); })); }
[Test] // TODO: fix jobs public void OnExitWorks([Values(CodeGenMode.NoJobs)] CodeGenMode mode) { SetupTestGraphMultipleFrames(mode, graphModel => { var group = graphModel.CreateComponentQuery("g"); var positionType = typeof(Translation).GenerateTypeHandle(Stencil); group.AddComponent(graphModel.Stencil, positionType, ComponentDefinitionFlags.None); group.AddComponent(graphModel.Stencil, typeof(Rotation).GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None); var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero); var update = graphModel.CreateNode <OnEndEntitiesNodeModel>("update", Vector2.zero); graphModel.CreateEdge(update.InstancePort, groupInstance.OutputPort); var log = update.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0); IVariableModel entityVariable = GraphModel.CreateVariableNode(update.FunctionParameterModels.Single(p => p.DataType == typeof(Entity).GenerateTypeHandle(Stencil)), Vector2.zero); GraphModel.CreateEdge(log.GetParameterPorts().First(), entityVariable.OutputPort); }, EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Rotation))), EachEntity((manager, i, e) => manager.AddComponent(e, typeof(Translation))), EachEntity((manager, i, e) => { LogAssert.NoUnexpectedReceived(); LogAssert.Expect(LogType.Log, $"Entity({i}:1)"); manager.RemoveComponent <Rotation>(e); }), EachEntity((manager, i, e) => {}) ); }
public void Test_RemoveSetPropertyMemberKeepsEdges([Values] TestingMode mode) { // test that removing a SetProperty member doesn't break the edge with it's Instance // i.e. here: check that removing Position keeps the link with Transform // |_TestFunction_____| // (Transform)---+-o Set Property | // | o Position | VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true); IVariableModel trVar = GraphModel.CreateVariableNode(trDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort); PropertyInfo propertyToAdd = typeof(Transform).GetProperty("position"); var newMember = new TypeMember { Path = new List <string> { propertyToAdd?.Name }, Type = propertyToAdd.GetUnderlyingType().GenerateTypeHandle(Stencil) }; setters.AddMember(newMember); TestPrereqActionPostreq(mode, () => { RefreshReference(ref method); RefreshReference(ref setters); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(2)); Assert.That(setters.Members.Count, Is.EqualTo(1)); return(new EditPropertyGroupNodeAction( EditPropertyGroupNodeAction.EditType.Remove, setters, newMember)); }, () => { RefreshReference(ref method); RefreshReference(ref setters); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.InputsByDisplayOrder.Count, Is.EqualTo(1)); Assert.That(setters.Members.Count, Is.EqualTo(0)); }); }
public void Test_ItemizeVariableNodeCommand([Values] TestingMode mode) { var declaration = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), "decl0", ModifierFlags.None, true); var variable = GraphModel.CreateVariableNode(declaration, Vector2.zero); var binary0 = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero); var binary1 = GraphModel.CreateNode <Type0FakeNodeModel>("Node1", Vector2.zero); IPortModel outputPort = variable.OutputPort; GraphModel.CreateEdge(binary0.Input0, outputPort); IPortModel outputPort1 = variable.OutputPort; GraphModel.CreateEdge(binary0.Input1, outputPort1); IPortModel outputPort2 = variable.OutputPort; GraphModel.CreateEdge(binary1.Input0, outputPort2); IPortModel outputPort3 = variable.OutputPort; GraphModel.CreateEdge(binary1.Input1, outputPort3); TestPrereqCommandPostreq(mode, () => { RefreshReference(ref variable); RefreshReference(ref binary0); RefreshReference(ref binary1); Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(1)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.Input0)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.Input1)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.Input0)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary1.Input1)); return(new ItemizeNodeCommand(variable)); }, () => { RefreshReference(ref variable); RefreshReference(ref binary0); RefreshReference(ref binary1); Assert.That(GetNodeCount(), Is.EqualTo(6)); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.Input0)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary0.Input1)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.Input0)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.Input1)); }); }
public void Test_ItemizeVariableNodeAction([Values] TestingMode mode) { var declaration = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true); var variable = GraphModel.CreateVariableNode(declaration, Vector2.zero); var binary0 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); var binary1 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); IPortModel outputPort = variable.OutputPort; GraphModel.CreateEdge(binary0.InputPortA, outputPort); IPortModel outputPort1 = variable.OutputPort; GraphModel.CreateEdge(binary0.InputPortB, outputPort1); IPortModel outputPort2 = variable.OutputPort; GraphModel.CreateEdge(binary1.InputPortA, outputPort2); IPortModel outputPort3 = variable.OutputPort; GraphModel.CreateEdge(binary1.InputPortB, outputPort3); TestPrereqActionPostreq(mode, () => { RefreshReference(ref variable); RefreshReference(ref binary0); RefreshReference(ref binary1); Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(1)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortB)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary1.InputPortB)); return(new ItemizeVariableNodeAction(variable)); }, () => { RefreshReference(ref variable); RefreshReference(ref binary0); RefreshReference(ref binary1); Assert.That(GetNodeCount(), Is.EqualTo(6)); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetAllNodes().OfType <VariableNodeModel>().Count(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1)); Assert.That(variable.OutputPort, Is.ConnectedTo(binary0.InputPortA)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary0.InputPortB)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.InputPortA)); Assert.That(variable.OutputPort, Is.Not.ConnectedTo(binary1.InputPortB)); }); }
public void Test_DeleteElementsAction_VariableUsage([Values] TestingMode mode) { var declaration0 = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true); var declaration1 = GraphModel.CreateGraphVariableDeclaration("decl1", typeof(int).GenerateTypeHandle(Stencil), true); var node0 = GraphModel.CreateVariableNode(declaration0, Vector2.zero); var node1 = GraphModel.CreateVariableNode(declaration0, Vector2.zero); var node2 = GraphModel.CreateVariableNode(declaration1, Vector2.zero); var node3 = GraphModel.CreateVariableNode(declaration1, Vector2.zero); var node4 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); var node5 = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); GraphModel.CreateEdge(node4.InputPortA, node0.OutputPort); GraphModel.CreateEdge(node4.InputPortB, node2.OutputPort); GraphModel.CreateEdge(node5.InputPortA, node1.OutputPort); GraphModel.CreateEdge(node5.InputPortB, node3.OutputPort); TestPrereqActionPostreq(mode, () => { declaration0 = GetVariableDeclaration(0); declaration1 = GetVariableDeclaration(1); Assert.That(GetNodeCount(), Is.EqualTo(6), "GetNodeCount1"); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(2), "GetVariableDeclarationCount"); return(new DeleteElementsAction(declaration0)); }, () => { declaration1 = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount2"); Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount"); }); TestPrereqActionPostreq(mode, () => { declaration1 = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount3"); Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount"); return(new DeleteElementsAction(declaration1)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2), "GetNodeCount"); Assert.That(GetEdgeCount(), Is.EqualTo(0), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); }); }
public void Test_DeleteElementsCommand_VariableUsage([Values] TestingMode mode) { var declaration0 = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), "decl0", ModifierFlags.None, true); var declaration1 = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), "decl1", ModifierFlags.None, true); var node0 = GraphModel.CreateVariableNode(declaration0, Vector2.zero); var node1 = GraphModel.CreateVariableNode(declaration0, Vector2.zero); var node2 = GraphModel.CreateVariableNode(declaration1, Vector2.zero); var node3 = GraphModel.CreateVariableNode(declaration1, Vector2.zero); var node4 = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero); var node5 = GraphModel.CreateNode <Type0FakeNodeModel>("Node1", Vector2.zero); GraphModel.CreateEdge(node4.Input0, node0.OutputPort); GraphModel.CreateEdge(node4.Input1, node2.OutputPort); GraphModel.CreateEdge(node5.Input0, node1.OutputPort); GraphModel.CreateEdge(node5.Input1, node3.OutputPort); TestPrereqCommandPostreq(mode, () => { declaration0 = GetVariableDeclaration(0); declaration1 = GetVariableDeclaration(1); Assert.That(GetNodeCount(), Is.EqualTo(6), "GetNodeCount1"); Assert.That(GetEdgeCount(), Is.EqualTo(4)); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(2), "GetVariableDeclarationCount"); return(new DeleteElementsCommand(declaration0)); }, () => { declaration1 = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount2"); Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount"); }); TestPrereqCommandPostreq(mode, () => { declaration1 = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(4), "GetNodeCount3"); Assert.That(GetEdgeCount(), Is.EqualTo(2), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(1), "GetVariableDeclarationCount"); return(new DeleteElementsCommand(declaration1)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2), "GetNodeCount"); Assert.That(GetEdgeCount(), Is.EqualTo(0), "EdgeCount"); Assert.That(GetVariableDeclarationCount(), Is.EqualTo(0)); }); }
public void NestedIterationSystem_DifferentGroups_DifferentComponents([Values] CodeGenMode mode) { SetupTestGraph(mode, g => { TypeHandle translationType = typeof(Translation).GenerateTypeHandle(Stencil); TypeHandle rotationType = typeof(Rotation).GenerateTypeHandle(Stencil); // query1 - Position ComponentQueryDeclarationModel query1 = GraphModel.CreateComponentQuery("g1"); query1.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None); IVariableModel query1Instance = GraphModel.CreateVariableNode(query1, Vector2.zero); // query2 - Rotation too ComponentQueryDeclarationModel query2 = GraphModel.CreateComponentQuery("g2"); query2.AddComponent(Stencil, rotationType, ComponentDefinitionFlags.None); IVariableModel query2Instance = GraphModel.CreateVariableNode(query2, Vector2.zero); // update query 1 OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero); GraphModel.CreateEdge(onUpdateModel.InstancePort, query1Instance.OutputPort); // nested update query 2 var forAllStack = GraphModel.CreateLoopStack <ForAllEntitiesStackModel>(Vector2.zero); var forAllNode = forAllStack.CreateLoopNode(onUpdateModel, 0) as ForAllEntitiesNodeModel; Assert.That(forAllNode, Is.Not.Null); GraphModel.CreateEdge(forAllNode.InputPort, query2Instance.OutputPort); GraphModel.CreateEdge(forAllStack.InputPort, forAllNode.OutputPort); // set query1.translation = ... SetPropertyGroupNodeModel set = forAllStack.CreateStackedNode <SetPropertyGroupNodeModel>("set"); var member = new TypeMember(TypeHandle.Float, new List <string> { nameof(Translation.Value), nameof(Translation.Value.x) }); set.AddMember(member); IVariableModel posComponent = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == translationType), Vector2.zero); GraphModel.CreateEdge(set.InstancePort, posComponent.OutputPort); ((FloatConstantModel)set.InputConstantsById[member.GetId()]).value = 2f; }, (manager, entityIndex, e) => { manager.AddComponentData(e, new Translation { Value = { x = entityIndex } }); manager.AddComponentData(e, new Rotation()); }, (manager, entityIndex, e) => Assert.That(manager.GetComponentData <Translation>(e).Value.x, Is.EqualTo(2f))); }
public void SendEventTest([Values] CodeGenMode mode) { SetupTestGraphMultipleFrames(mode, g => { ComponentQueryDeclarationModel query = GraphModel.CreateComponentQuery("g1"); TypeHandle positionType = typeof(Translation).GenerateTypeHandle(Stencil); query.AddComponent(Stencil, positionType, ComponentDefinitionFlags.None); IVariableModel queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero); OnUpdateEntitiesNodeModel onUpdateModel = GraphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero); GraphModel.CreateEdge(onUpdateModel.InstancePort, queryInstance.OutputPort); TypeHandle eventTypeHandle = typeof(UnitTestEvent).GenerateTypeHandle(Stencil); SendEventNodeModel set = onUpdateModel.CreateStackedNode <SendEventNodeModel>("set", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle); TypeHandle entityType = typeof(Entity).GenerateTypeHandle(Stencil); IVariableModel entityVar = GraphModel.CreateVariableNode(onUpdateModel.FunctionParameterModels.Single(p => p.DataType == entityType), Vector2.zero); GraphModel.CreateEdge(set.EntityPort, entityVar.OutputPort); var firstFieldInput = set.FieldInputs.First(); ((FloatConstantModel)set.InputConstantsById[firstFieldInput.UniqueId]).value = 2f; }, // Add translation to even entities EachEntity((manager, i, e) => { manager.AddComponent(e, typeof(Translation)); manager.World.CreateSystem <InitializationSystemGroup>(); }), (manager, entities) => { EventSystem <UnitTestEvent> eventSystem = manager.World.GetExistingSystem <EventSystem <UnitTestEvent> >(); Assert.That(eventSystem, Is.Not.Null); eventSystem.Update(); }, // OnUpdate should have added a buffer and one event EachEntity((manager, i, e) => { DynamicBuffer <UnitTestEvent> buffer = default; Assert.DoesNotThrow(() => buffer = manager.GetBuffer <UnitTestEvent>(e)); Assert.That(buffer.IsCreated, Is.True); Assert.That(buffer.Length, Is.EqualTo(1)); Assert.That(buffer[0].i, Is.EqualTo(2f)); }) ); }
public void ConnectingADifferentNodePreservesConnections([Values] TestingMode mode) { const string nodeName = "Node0"; { var iDecl = GraphModel.CreateGraphVariableDeclaration(TypeHandle.Int, "myInt", ModifierFlags.None, true); GraphModel.CreateVariableNode(iDecl, Vector2.up); var vDecl = GraphModel.CreateGraphVariableDeclaration(typeof(Vector3).GenerateTypeHandle(), "myVec", ModifierFlags.None, true); var myVec = GraphModel.CreateVariableNode(vDecl, Vector2.left); var getProperty = GraphModel.CreateNode <Type0FakeNodeModel>(nodeName, Vector2.zero); GraphModel.CreateEdge(getProperty.Input0, myVec.OutputPort); var log1 = GraphModel.CreateNode <Type0FakeNodeModel>("log1"); var log2 = GraphModel.CreateNode <Type0FakeNodeModel>("log2"); GraphModel.CreateEdge(log1.Input0, getProperty.Output0); GraphModel.CreateEdge(log2.Input0, getProperty.Output1); } TestPrereqCommandPostreq(mode, () => { var log1 = GraphModel.NodeModels[3] as Type0FakeNodeModel; var log2 = GraphModel.NodeModels[4] as Type0FakeNodeModel; var myInt = GetAllNodes().OfType <VariableNodeModel>().Single(n => n.GetDataType() == TypeHandle.Int); var getProperty = GetAllNodes().OfType <Type0FakeNodeModel>().First(n => n.Title == nodeName); Assert.That(myInt.OutputPort.IsConnected, Is.False); Assert.That(log1?.Input0, Is.ConnectedTo(getProperty.Output0)); Assert.That(log2?.Input0, Is.ConnectedTo(getProperty.Output1)); return(new CreateEdgeCommand(log1?.Input0, myInt.OutputPort, new List <IEdgeModel> { GraphModel.GetEdgesConnections(log1?.Input0).Single() })); }, () => { var log1 = GraphModel.NodeModels[3] as Type0FakeNodeModel; var log2 = GraphModel.NodeModels[4] as Type0FakeNodeModel; var myInt = GetAllNodes().OfType <VariableNodeModel>().Single(n => n.GetDataType() == TypeHandle.Int); var getProperty = GetAllNodes().OfType <Type0FakeNodeModel>().First(n => n.Title == nodeName); Assert.That(myInt.OutputPort.IsConnected, Is.True); Assert.That(getProperty.Output0.IsConnected, Is.False); Assert.That(log1?.Input0, Is.ConnectedTo(myInt.OutputPort)); Assert.That(log2?.Input0, Is.ConnectedTo(getProperty.Output1)); }); }
public void MultipleOnUpdateEntities([Values] CodeGenMode mode) { SetupTestGraph(mode, graph => { var translationType = typeof(Translation).GenerateTypeHandle(Stencil); var query = GraphModel.CreateComponentQuery("g1"); query.AddComponent(Stencil, translationType, ComponentDefinitionFlags.None); var queryInstance = GraphModel.CreateVariableNode(query, Vector2.zero); CreateUpdateAndLogEntity(graph, queryInstance); CreateUpdateAndLogEntity(graph, queryInstance); }, (manager, index, entity) => manager.AddComponentData(entity, new Translation()), (manager, index, entity) => Assert.Pass() ); }
public void ExtractSingleNodeWithSameInputsCreatesOnlyOneMacroInput() { // a + a FunctionCallNodeModel[] log; CreateStackAndLogs(out _, out log); var binOp = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); var varA = GraphModel.CreateVariableNode(m_ADecl, Vector2.zero); GraphModel.CreateEdge(log[0].GetParameterPorts().First(), binOp.OutputPort); GraphModel.CreateEdge(binOp.InputPortA, varA.OutputPort); GraphModel.CreateEdge(binOp.InputPortB, varA.OutputPort); TestExtractMacro(new[] { binOp }, inputs: new IO(varA.OutputPort), outputs: new IO(log[0].GetParameterPorts().First())); }
public void Test_UpdateTooltipAction([Values] TestingMode mode) { VariableDeclarationModel declaration = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true); declaration.Tooltip = "asd"; GraphModel.CreateVariableNode(declaration, Vector2.zero); GraphModel.CreateVariableNode(declaration, Vector2.zero); TestPrereqActionPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("asd")); return(new UpdateTooltipAction(declaration, "qwe")); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("qwe")); }); TestPrereqActionPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("qwe")); return(new UpdateTooltipAction(declaration, "asd")); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("asd")); }); }
public void Test_UpdateTypeCommand_UpdatesVariableReferences([Values] TestingMode mode) { TypeHandle intType = typeof(int).GenerateTypeHandle(); TypeHandle floatType = typeof(float).GenerateTypeHandle(); var declaration = GraphModel.CreateGraphVariableDeclaration(intType, "decl0", ModifierFlags.None, true); GraphModel.CreateVariableNode(declaration, Vector2.zero); GraphModel.CreateVariableNode(declaration, Vector2.zero); TestPrereqCommandPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.DataType, Is.EqualTo(intType)); Assert.That(declaration.InitializationModel.Type, Is.EqualTo(typeof(int))); foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>()) { Assert.That(variableNodeModel.OutputPort?.DataTypeHandle, Is.EqualTo(intType)); } return(new ChangeVariableTypeCommand(declaration, floatType)); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.DataType, Is.EqualTo(floatType)); Assert.That(declaration.InitializationModel.Type, Is.EqualTo(typeof(float))); foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>()) { Assert.That(variableNodeModel.OutputPort?.DataTypeHandle, Is.EqualTo(floatType)); } }); }
public void Test_UpdateTooltipCommand([Values] TestingMode mode) { var declaration = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), "decl0", ModifierFlags.None, true) as VariableDeclarationModel; declaration.Tooltip = "asd"; GraphModel.CreateVariableNode(declaration, Vector2.zero); GraphModel.CreateVariableNode(declaration, Vector2.zero); TestPrereqCommandPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("asd")); return(new UpdateTooltipCommand(declaration, "qwe")); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("qwe")); }); TestPrereqCommandPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("qwe")); return(new UpdateTooltipCommand(declaration, "asd")); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.Tooltip, Is.EqualTo("asd")); }); }
public void Test_ChangeStackedNode_ToSameNodeModel([Values] TestingMode mode) { var stackModel = GraphModel.CreateStack(string.Empty, Vector2.zero); var nodeA = stackModel.CreateStackedNode <Type0FakeNodeModel>("A"); var unaryNode = stackModel.CreateUnaryStatementNode(UnaryOperatorKind.PostDecrement, 1); var nodeB = stackModel.CreateStackedNode <Type0FakeNodeModel>("B"); var variableNode = GraphModel.CreateVariableNode( ScriptableObject.CreateInstance <VariableDeclarationModel>(), Vector2.zero); GraphModel.CreateEdge(unaryNode.InputPort, variableNode.OutputPort); var db = new GraphElementSearcherDatabase(Stencil).AddUnaryOperators().Build(); var item = (StackNodeModelSearcherItem)db.Search("postincr", out _)[0]; TestPrereqActionPostreq(mode, () => { Assert.That(stackModel.NodeModels.Count, Is.EqualTo(3)); Assert.That(nodeA, Has.IndexInStack(0, stackModel)); var oldNode = GetStackedNode(0, 1) as UnaryOperatorNodeModel; Assert.NotNull(oldNode); Assert.That(nodeB, Has.IndexInStack(2, stackModel)); Assert.That(variableNode.OutputPort, Is.ConnectedTo(oldNode.InputPort)); return(new ChangeStackedNodeAction(oldNode, stackModel, item)); }, () => { Assert.That(stackModel.NodeModels.Count, Is.EqualTo(3)); Assert.That(nodeA, Has.IndexInStack(0, stackModel)); Assert.That(unaryNode.IsStacked, Is.False); Assert.That(nodeB, Has.IndexInStack(2, stackModel)); var newNode = GetStackedNode(0, 1); Assert.That(newNode, Is.Not.Null); Assert.That(newNode, Is.InstanceOf <UnaryOperatorNodeModel>()); var newUnaryNode = (UnaryOperatorNodeModel)newNode; Assert.That(newUnaryNode.kind, Is.EqualTo(UnaryOperatorKind.PostIncrement)); Assert.That(variableNode.OutputPort, Is.ConnectedTo(newUnaryNode.InputPort)); }); }
public void Test_UpdateTypeAction_UpdatesVariableReferences([Values] TestingMode mode) { TypeHandle intType = typeof(int).GenerateTypeHandle(Stencil); TypeHandle floatType = typeof(float).GenerateTypeHandle(Stencil); VariableDeclarationModel declaration = GraphModel.CreateGraphVariableDeclaration("decl0", intType, true); GraphModel.CreateVariableNode(declaration, Vector2.zero); GraphModel.CreateVariableNode(declaration, Vector2.zero); TestPrereqActionPostreq(mode, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.DataType, Is.EqualTo(intType)); Assert.That(((ConstantNodeModel)declaration.InitializationModel).Type, Is.EqualTo(typeof(int))); foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>()) { Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(intType)); } return(new UpdateTypeAction(declaration, floatType)); }, () => { declaration = GetVariableDeclaration(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(declaration.DataType, Is.EqualTo(floatType)); Assert.That(((ConstantNodeModel)declaration.InitializationModel).Type, Is.EqualTo(typeof(float))); foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>()) { Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(floatType)); } }); }
public void Test_DisconnectSetPropertyKeepsPortType([Values] TestingMode mode) { VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true); IVariableModel trVar = GraphModel.CreateVariableNode(trDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort); setters.AddMember( new TypeMember { Path = new List <string> { "position" }, Type = Stencil.GenerateTypeHandle(typeof(Vector3)) } ); IConstantNodeModel constToken = GraphModel.CreateConstantNode("v3", typeof(Vector3).GenerateTypeHandle(Stencil), Vector2.left * 200); IEdgeModel edge = GraphModel.CreateEdge(setters.GetPortsForMembers().First(), constToken.OutputPort); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); }); }
public void Test_DisconnectSetPropertyInstanceSetsRightPortType(TestingMode mode, int inputIndex, Type expectedPortType) { VariableDeclarationModel goDecl = GraphModel.CreateGraphVariableDeclaration("go", typeof(GameObject).GenerateTypeHandle(Stencil), true); IVariableModel goVar = GraphModel.CreateVariableNode(goDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); IEdgeModel edge = GraphModel.CreateEdge(setters.InstancePort, goVar.OutputPort); PropertyInfo propertyInfo = typeof(Transform).GetProperty("position"); var newMember = new TypeMember { Path = new List <string> { propertyInfo?.Name }, Type = typeof(Transform).GenerateTypeHandle(Stencil) }; setters.AddMember(newMember); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.InstancePort.DataType, Is.EqualTo(TypeHandle.Unknown)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); }); }