public void TestRandomNodeModelAllowsVariousTypes([Values] RandomSupportedTypes randomType, [Values] RandomNodeModel.ParamVariant variant) { GUID nodeGuid = GUID.Generate(); TestPrereqActionPostreq(TestingMode.Action, () => { var n = GraphModel.CreateNode <RandomNodeModel>(RandomNodeModel.MakeTitle(RandomNodeModel.DefaultMethod), preDefineSetup: m => { m.Variant = variant; m.MethodBaseName = randomType.ToString(); }, guid: nodeGuid); Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(1)); return(new RefreshUIAction(UpdateFlags.All)); }, () => { Assert.That(GraphModel.NodeModels.Count, Is.EqualTo(1)); Assert.That(GraphModel.NodesByGuid.TryGetValue(nodeGuid, out var n), Is.True); var rng = n as RandomNodeModel; Assert.That(rng, Is.Not.Null); Assert.That(rng.RngMethod.Name, Does.EndWith(randomType.ToString())); int expectedParams = 0; if (randomType != RandomSupportedTypes.Bool && variant != RandomNodeModel.ParamVariant.NoParameters) { expectedParams = variant == RandomNodeModel.ParamVariant.Max ? 1 : 2; } Assert.That(rng.RngMethod.GetParameters().Length, Is.EqualTo(expectedParams)); });
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); }