Пример #1
0
        public void Test_CreateNodeFromSearcherCommand([Values] TestingMode mode)
        {
            var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel);

            Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb);
            var db   = gedb.Build();
            var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0];

            TestPrereqCommandPostreq(mode,
                                     () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(0));
                return(new CreateNodeFromSearcherCommand(new Vector2(100, 200), item,
                                                         new SerializableGUID("0123456789abcdef0123456789abcdef")));
            },
                                     () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(1));
                Assert.That(GraphModel.NodeModels.First(), Is.TypeOf <Type0FakeNodeModel>());
                Assert.AreEqual(new SerializableGUID("0123456789abcdef0123456789abcdef"),
                                GraphModel.NodeModels.First().Guid);
                Assert.That(GraphModel.NodeModels.First().Position,
                            Is.EqualTo(new Vector2(100, 200)));
            }
                                     );
        }
Пример #2
0
        public void Test_CreateNodeFromOutputPort(TestingMode testingMode)
        {
            var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel);

            Type3FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb);
            var db   = gedb.Build();
            var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type3FakeNodeModel))[0];

            var node0 = GraphModel.CreateNode <Type3FakeNodeModel>("Node0", Vector2.zero);

            TestPrereqCommandPostreq(testingMode,
                                     () =>
            {
                RefreshReference(ref node0);
                var output0 = node0.Output;
                Assert.That(GetNodeCount(), Is.EqualTo(1));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                return(new CreateNodeFromPortCommand(new[] { output0 }, Vector2.down, item));
            },
                                     () =>
            {
                RefreshReference(ref node0);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));

                var newNode = GetNode(1);
                Assert.That(newNode, Is.TypeOf <Type3FakeNodeModel>());

                var newEdge = GetEdge(0);
                Assert.That(newEdge.ToPort.DataTypeHandle, Is.EqualTo(newEdge.FromPort.DataTypeHandle));

                var portModel = node0.Output;
                Assert.That(portModel.GetConnectedPorts().Single(), Is.EqualTo(newNode.InputsByDisplayOrder.First()));
            });
        }
Пример #3
0
        public void TestCreateNodeOnEdge_WithOutputNodeConnectedToUnknown([Values] TestingMode mode)
        {
            var constantNode = GraphModel.CreateConstantNode(typeof(int).GenerateTypeHandle(), "int1", Vector2.zero);
            var addNode      = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero);

            GraphModel.CreateEdge(addNode.Input0, constantNode.OutputPort);
            GraphModel.CreateEdge(addNode.Input1, constantNode.OutputPort);

            var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel);

            Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb);
            var db   = gedb.Build();
            var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0];

            TestPrereqCommandPostreq(mode,
                                     () =>
            {
                RefreshReference(ref addNode);
                RefreshReference(ref constantNode);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));

                Assert.That(addNode, Is.Not.Null);
                Assert.That(addNode.Input0, Is.ConnectedTo(constantNode.OutputPort));
                var edge = GraphModel.EdgeModels.First();
                return(new CreateNodeOnEdgeCommand(edge, Vector2.zero, item));
            },
                                     () =>
            {
                RefreshReference(ref addNode);
                RefreshReference(ref constantNode);
                var multiplyNode = GraphModel.NodeModels.OfType <Type0FakeNodeModel>().ToList()[1];

                Assert.IsNotNull(multiplyNode);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(3));
                Assert.That(constantNode.OutputPort, Is.ConnectedTo(multiplyNode.Input0));
                Assert.That(multiplyNode.Output0, Is.ConnectedTo(addNode.Input0));
                Assert.That(constantNode.OutputPort, Is.Not.ConnectedTo(addNode.Input0));
            }
                                     );
        }
Пример #4
0
        public override List <SearcherDatabase> GetDynamicSearcherDatabases(IPortModel portModel)
        {
            var dbs = base.GetDynamicSearcherDatabases(portModel);

            if (portModel == null) // graph searcher
            {
                var    rngDb = new GraphElementSearcherDatabase(m_Stencil);
                string title = RandomNodeModel.k_DefaultRngTitle;
                var    node  = new GraphNodeModelSearcherItem(
                    new NodeSearcherItemData(typeof(RandomNodeModel)),
                    data => data.CreateNode <RandomNodeModel>(title),
                    title
                    );
                rngDb.Items.Add(node);
                dbs.Add(rngDb.Build());
                return(dbs);
            }

            // input to graph
            if (RandomNodeModel.RngByType.TryGetValue(portModel.DataType.Resolve(portModel.NodeModel.GraphModel.Stencil), out var methods))
            {
                var rngDb = new GraphElementSearcherDatabase(m_Stencil);
                foreach (var method in methods)
                {
                    if (method == RandomNodeModel.DefaultMethod)
                    {
                        continue;
                    }
                    string title = RandomNodeModel.MakeTitle(method);
                    var    node  = new GraphNodeModelSearcherItem(
                        new NodeSearcherItemData(typeof(RandomNodeModel)),
                        data => data.CreateNode <RandomNodeModel>(title),
                        title
                        );
                    rngDb.Items.Add(node);
                }
                dbs.Add(rngDb.Build());
            }
            return(dbs);
        }
Пример #5
0
        public void TestCreateNodeOnEdge_BothPortsConnected([Values] TestingMode mode)
        {
            var constant = GraphModel.CreateConstantNode(typeof(int).GenerateTypeHandle(), "int", Vector2.zero);
            var unary    = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero);
            var edge     = GraphModel.CreateEdge(unary.Input0, constant.OutputPort);

            var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel);

            Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb);
            var db   = gedb.Build();
            var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0];

            TestPrereqCommandPostreq(mode,
                                     () =>
            {
                RefreshReference(ref unary);
                RefreshReference(ref constant);
                edge = GetEdge(0);
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(unary.Input0, Is.ConnectedTo(constant.OutputPort));
                return(new CreateNodeOnEdgeCommand(edge, Vector2.zero, item));
            },
                                     () =>
            {
                RefreshReference(ref unary);
                RefreshReference(ref constant);
                RefreshReference(ref edge);
                var unary2 = GraphModel.NodeModels.OfType <Type0FakeNodeModel>().ToList()[1];

                Assert.IsNotNull(unary2);
                Assert.That(GetNodeCount(), Is.EqualTo(3));
                Assert.That(GetEdgeCount(), Is.EqualTo(2));
                Assert.That(constant.OutputPort, Is.ConnectedTo(unary2.Input0));
                Assert.That(unary2.Output0, Is.ConnectedTo(unary.Input0));
                Assert.IsFalse(GraphModel.EdgeModels.Contains(edge));
            }
                                     );
        }