Esempio n. 1
0
        public void AddConstants_Allocate_SumGetsImmutableValueSource()
        {
            DfirRoot function = DfirRoot.Create();
            var      add      = new FunctionalNode(function.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            ConnectConstantToInputTerminal(add.InputTerminals[0], NITypes.Int32, false);
            ConnectConstantToInputTerminal(add.InputTerminals[1], NITypes.Int32, false);

            FunctionVariableStorage valueStorage = RunAllocator(function);

            ValueSource sumSource = valueStorage.GetValueSourceForVariable(add.OutputTerminals[2].GetTrueVariable());

            Assert.IsInstanceOfType(sumSource, typeof(ImmutableValueSource));
        }
Esempio n. 2
0
        public void PanickingAndNonpanickingUnwrapOptionIntoAddAndOutput_Execute_NoOutputValue()
        {
            DfirRoot       function   = DfirRoot.Create();
            FunctionalNode unwrapNone = CreatePanickingUnwrapOption(function.BlockDiagram);
            var            unwrapSome = new FunctionalNode(function.BlockDiagram, Signatures.UnwrapOptionType);

            ConnectSomeOfIntegerToInputTerminal(unwrapSome.InputTerminals[0], 5);
            var add = new FunctionalNode(function.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            Wire.Create(function.BlockDiagram, unwrapNone.OutputTerminals[0], add.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, unwrapSome.OutputTerminals[0], add.InputTerminals[1]);
            ConnectOutputToOutputTerminal(add.OutputTerminals[2]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            AssertNoOutput(executionInstance);
        }
Esempio n. 3
0
        public void CreateParallelYieldPromisesAwaitAndSumResults_ExecutionFinishesAndSumReadFromInspect()
        {
            DfirRoot function   = DfirRoot.Create();
            var      yieldNode0 = new FunctionalNode(function.BlockDiagram, Signatures.YieldType);

            ConnectConstantToInputTerminal(yieldNode0.InputTerminals[0], NITypes.Int32, 5, false);
            var yieldNode1 = new FunctionalNode(function.BlockDiagram, Signatures.YieldType);

            ConnectConstantToInputTerminal(yieldNode1.InputTerminals[0], NITypes.Int32, 6, false);
            var add = new FunctionalNode(function.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            Wire.Create(function.BlockDiagram, yieldNode0.OutputTerminals[0], add.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, yieldNode1.OutputTerminals[0], add.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(add.OutputTerminals[2]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 11);
        }
Esempio n. 4
0
        public void CreateNotifierPairDropNotifierWriterAndGetNotifierValue_Execute_ExecutionFinishesAndNoValueOutput()
        {
            DfirRoot function           = DfirRoot.Create();
            var      createNotifierPair = new FunctionalNode(function.BlockDiagram, Signatures.CreateNotifierPairType);
            var      getNotifierValue   = new FunctionalNode(function.BlockDiagram, Signatures.GetNotifierValueType);

            Wire.Create(function.BlockDiagram, createNotifierPair.OutputTerminals[0], getNotifierValue.InputTerminals[0]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(getNotifierValue.OutputTerminals[0]);
            // Create a frame that adds to the unwrapped value to coerce it to Int32, even though the value should be None
            Frame frame = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOption = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, inspect.OutputTerminals[0], unwrapOption.InputTerminals[0]);
            var add = new FunctionalNode(frame.Diagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            Wire.Create(frame.Diagram, unwrapOption.OutputTerminals[0], add.InputTerminals[0]);
            ConnectConstantToInputTerminal(add.InputTerminals[1], NITypes.Int32, 0, false);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsNoneInteger(inspectValue);
        }
Esempio n. 5
0
 public void ModulusOfTwoI32s_Execute_CorrectResultValue()
 {
     TestPureBinaryI32Operation(Signatures.DefinePureBinaryFunction("Modulus", PFTypes.Int32, PFTypes.Int32), 7, 5, 2);
 }
Esempio n. 6
0
 public void DivideTwoI32s_Execute_CorrectResultValue()
 {
     TestPureBinaryI32Operation(Signatures.DefinePureBinaryFunction("Divide", PFTypes.Int32, PFTypes.Int32), 6, 5, 1);
 }
Esempio n. 7
0
 public void MultiplyTwoI32s_Execute_CorrectResultValue()
 {
     TestPureBinaryI32Operation(Signatures.DefinePureBinaryFunction("Multiply", PFTypes.Int32, PFTypes.Int32), 6, 5, 30);
 }
Esempio n. 8
0
        public void PanickingMethodCallWithTwoOutputsThatDoesNotPanicIntoAdd_Execute_CorrectValue()
        {
            using (FeatureToggleSupport.TemporarilyEnableFeature(RebarFeatureToggles.ParametersAndCalls))
            {
                string calleeName = "callee";
                NIType calleeType = DefineFunctionTypeWithTwoIntOuts(calleeName);
                CompilableDefinitionName calleeDefinitionName = CreateTestCompilableDefinitionName(calleeName);
                DfirRoot       calleeFunction      = calleeType.CreateFunctionFromSignature(calleeDefinitionName);
                DataAccessor   outputDataAccessor0 = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[0], Direction.Input);
                DataAccessor   outputDataAccessor1 = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[1], Direction.Input);
                FunctionalNode unwrap = new FunctionalNode(calleeFunction.BlockDiagram, Signatures.UnwrapOptionType);
                ConnectSomeOfIntegerToInputTerminal(unwrap.InputTerminals[0], 1);
                Wire.Create(calleeFunction.BlockDiagram, unwrap.OutputTerminals[0], outputDataAccessor0.Terminal, outputDataAccessor1.Terminal);
                DfirRoot       callerFunction = DfirRoot.Create();
                var            methodCall     = new MethodCallNode(callerFunction.BlockDiagram, calleeDefinitionName, calleeType);
                FunctionalNode add            = new FunctionalNode(callerFunction.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));
                Wire.Create(callerFunction.BlockDiagram, methodCall.OutputTerminals[0], add.InputTerminals[0]);
                Wire.Create(callerFunction.BlockDiagram, methodCall.OutputTerminals[1], add.InputTerminals[1]);
                FunctionalNode inspect = ConnectInspectToOutputTerminal(add.OutputTerminals[2]);

                TestExecutionInstance executionInstance = CompileAndExecuteFunction(callerFunction, calleeFunction);

                byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
                AssertByteArrayIsInt32(inspectValue, 2);
            }
        }
Esempio n. 9
0
 protected PureBinaryPrimitive(BinaryPrimitiveOps binaryOp)
     : base(Signatures.DefinePureBinaryFunction(binaryOp.ToString(), binaryOp.GetExpectedInputType(), binaryOp.GetExpectedInputType()))
 {
 }
Esempio n. 10
0
 public void XorTwoBooleans_Execute_CorrectResultValue()
 {
     TestPureBinaryBooleanOperation(Signatures.DefinePureBinaryFunction("Xor", NITypes.Boolean, NITypes.Boolean), true, false, true);
 }
Esempio n. 11
0
 public void SubtractTwoI32s_Execute_CorrectResultValue()
 {
     TestPureBinaryI32Operation(Signatures.DefinePureBinaryFunction("Subtract", NITypes.Int32, NITypes.Int32), 6, 5, 1);
 }
Esempio n. 12
0
 public void AndTwoBooleans_Execute_CorrectResultValue()
 {
     TestPureBinaryBooleanOperation(Signatures.DefinePureBinaryFunction("And", PFTypes.Boolean, PFTypes.Boolean), true, false, false);
 }