public void RemoveOperator_SourceOperatorWithConnection_operatorAndConnectionRemoved() { var metaCompOp = new MetaOperator(Guid.NewGuid()); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); Operator op = metaCompOp.CreateOperator(Guid.NewGuid()); Operator float1 = op.InternalOps[0]; Operator float2 = op.InternalOps[1]; op.InsertConnectionAt(new Connection(float1, float1.Outputs[0], float2, float2.Inputs[0], 0)); Assert.AreEqual(float1.Outputs[0], float2.Inputs[0].Connections[0]); List <System.EventArgs> eventArgs = new List <System.EventArgs>(); op.ConnectionRemovedEvent += (o, e) => { eventArgs.Add(e); }; op.OperatorRemovedEvent += (o, e) => { eventArgs.Add(e); }; op.RemoveOperator(float1); Assert.AreEqual(2, eventArgs.Count); var connectionChangedEventArgs = eventArgs[0] as ConnectionChangedEventArgs; Assert.AreNotEqual(null, connectionChangedEventArgs); Assert.AreEqual(float1, connectionChangedEventArgs.Connection.SourceOp); Assert.AreEqual(float1.Outputs[0], connectionChangedEventArgs.Connection.SourceOpPart); Assert.AreEqual(float2, connectionChangedEventArgs.Connection.TargetOp); Assert.AreEqual(float2.Inputs[0], connectionChangedEventArgs.Connection.TargetOpPart); Assert.AreNotEqual(null, eventArgs[1] as OperatorChangedEventArgs); Assert.AreEqual(1, op.InternalOps.Count); Assert.AreEqual(float2, op.InternalOps[0]); Assert.AreEqual(0, float2.Inputs[0].Connections.Count); }
public void testInstanceRead() { var json = new Json(); StringBuilder sb = new StringBuilder(); json.Writer = new JsonTextWriter(new StringWriter(sb)); json.Writer.Formatting = Formatting.Indented; var op = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()).CreateOperator(Guid.NewGuid()); op.Inputs[0].Func = Utilities.CreateValueFunction(new Float(17.0f)); json.WriteOperator(op); op.Inputs[0].Func = Utilities.CreateValueFunction(new Float(0.0f)); var jsonData = sb.ToString(); using (var sr = new StringReader(jsonData)) using (var reader = new JsonTextReader(sr)) { json.Reader = reader; json.ReadAndSetOperatorValues(op); } var context = new OperatorPartContext(); Assert.AreEqual(op.Inputs[0].Eval(context).Value, 17.0f); }
public static MetaOperator CreateMetaFloatWithoutConnections() { var metaOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()); metaOp.RemoveConnection(new MetaConnection(Guid.Empty, metaOp.Inputs[0].ID, Guid.Empty, metaOp.Outputs[0].ID), 0); Assert.AreEqual(0, metaOp.Connections.Count); return(metaOp); }
public void testInstanceWrite() { var json = new Json(); StringBuilder sb = new StringBuilder(); json.Writer = new JsonTextWriter(new StringWriter(sb)); json.Writer.Formatting = Formatting.Indented; json.WriteOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()).CreateOperator(Guid.NewGuid())); }
public void CollectAllMetaOperators_SingleOperator_Returns1() { var metaOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()); var opInstance = metaOp.CreateOperator(Guid.NewGuid()); var output = opInstance.Outputs.First(); var collectedMetaOperators = new HashSet <MetaOperator>(); output.CollectAllMetaOperators(collectedMetaOperators); Assert.AreEqual(1, collectedMetaOperators.Count); }
public void Initialize() { var metaOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()); _operator = metaOp.CreateOperator(Guid.NewGuid()); var parentMeta = MetaOperatorTests.CreateGenericMultiInputMetaOperator(Guid.NewGuid()); _parentOperator = parentMeta.CreateOperator(Guid.NewGuid()); _parentOperator.InternalOps.Add(_operator); _operator.Parent = _parentOperator; MetaManager.Instance.AddMetaOperator(parentMeta.ID, parentMeta); MetaManager.Instance.AddMetaOperator(metaOp.ID, metaOp); }
public void CollectAllMetaOperators_2NestedOperatorsWithoutConnection_Returns2() { var metaOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()); metaOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); var opInstance = metaOp.CreateOperator(Guid.NewGuid()); var output = opInstance.Outputs.First(); var collectedMetaOperators = new HashSet <MetaOperator>(); output.CollectAllMetaOperators(collectedMetaOperators); Assert.AreEqual(2, collectedMetaOperators.Count); }
public void InsertConnectionAt_Inserting2ndConnectionAtIndex0ToMultiInput_connectionIsInsertedAtFront() { var metaCompOp = new MetaOperator(Guid.NewGuid()); metaCompOp.AddOperator(MetaOperatorTests.CreateGenericMultiInputMetaOperator()); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); metaCompOp.AddOperator(MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid())); Operator op = metaCompOp.CreateOperator(Guid.NewGuid()); Operator multiply = op.InternalOps[0]; Operator float1 = op.InternalOps[1]; Operator float2 = op.InternalOps[2]; op.InsertConnectionAt(new Connection(float1, float1.Outputs[0], multiply, multiply.Inputs[0], 0)); op.InsertConnectionAt(new Connection(float2, float2.Outputs[0], multiply, multiply.Inputs[0], 0)); Assert.AreEqual(multiply.Inputs[0].Connections[0], float2.Outputs[0]); }
public void testMetaRead() { var json = new Json(); StringBuilder sb = new StringBuilder(); json.Writer = new JsonTextWriter(new StringWriter(sb)); json.Writer.Formatting = Formatting.Indented; var meta = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid());; json.WriteMetaOperator(meta); var jsonData = sb.ToString(); using (var sr = new StringReader(jsonData)) using (var reader = new JsonTextReader(sr)) { json.Reader = reader; var metaOp = json.ReadMetaOperator(new MetaManager()); } }
public void Type_GenericTypeWithChangingInputType_OutputGetsDisconnected() { var parentOp = Utilities.CreateEmptyOperator(); var genericOp = MetaOperatorTests.CreateGenericMultiInputMetaOperator().CreateOperator(Guid.NewGuid()); var floatOutputOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()).CreateOperator(Guid.NewGuid()); var floatInputOp = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()).CreateOperator(Guid.NewGuid()); var textInputOp = MetaOperatorTests.CreateTextMetaOperator().CreateOperator(Guid.NewGuid()); parentOp.AddOperator(genericOp); parentOp.AddOperator(floatOutputOp); parentOp.AddOperator(floatInputOp); parentOp.AddOperator(textInputOp); parentOp.InsertConnectionAt(new Connection(floatInputOp, floatInputOp.Outputs[0], genericOp, genericOp.Inputs[0], 0)); parentOp.InsertConnectionAt(new Connection(genericOp, genericOp.Outputs[0], floatOutputOp, floatOutputOp.Inputs[0], 0)); parentOp.ReplaceConnectionAt(new Connection(textInputOp, textInputOp.Inputs[0], genericOp, genericOp.Inputs[0], 0)); Assert.AreEqual(0, floatOutputOp.Inputs[0].Connections.Count()); }
public static MetaOperator CreateCombinedMetaOperator(Guid metaId) { var inputGuid = Guid.NewGuid(); var outputGuid = Guid.NewGuid(); var opInstanceGuid = Guid.NewGuid(); var op = MetaOperatorTests.CreateFloatMetaOperator(Guid.NewGuid()); var inputs = new List <MetaInput>() { new MetaInput(inputGuid, "Input", BasicMetaTypes.FloatMeta, new Float(0.0f), false) }; return(new MetaOperator(metaId) { Name = "Float", Inputs = inputs, Outputs = new[] { new MetaOutput(outputGuid, "Output", BasicMetaTypes.FloatMeta) }.ToList(), Operators = new MetaOpEntryContainer() { { opInstanceGuid, new MetaOpEntry(op, new MetaOperator.InstanceProperties(op.Inputs)) } }, Connections = new[] { new MetaConnection(Guid.Empty, inputGuid, opInstanceGuid, op.Inputs[0].ID), new MetaConnection(opInstanceGuid, op.Outputs[0].ID, Guid.Empty, outputGuid) }.ToList(), }); }