public void BranchedStringSliceWire_Execute_BothSinksHaveCorrectValues()
        {
            DfirRoot           function            = DfirRoot.Create();
            Constant           stringSliceConstant = Constant.Create(function.BlockDiagram, "test", DataTypes.StringSliceType.CreateImmutableReference());
            var                inspect1Node        = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            ExplicitBorrowNode borrow1             = ConnectExplicitBorrowToInputTerminals(inspect1Node.InputTerminals[0]);
            var                inspect2Node        = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            ExplicitBorrowNode borrow2             = ConnectExplicitBorrowToInputTerminals(inspect2Node.InputTerminals[0]);

            Wire.Create(function.BlockDiagram, stringSliceConstant.OutputTerminal, borrow1.InputTerminals[0], borrow2.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

#if LLVM_TEST
            const int stringSliceReferenceSize = 16;
#else
            const int stringSliceReferenceSize = 8;
#endif

            byte[] inspect1Value = executionInstance.GetLastValueFromInspectNode(inspect1Node);
            Assert.AreEqual(stringSliceReferenceSize, inspect1Value.Length);
            byte[] inspect2Value = executionInstance.GetLastValueFromInspectNode(inspect2Node);
            Assert.AreEqual(stringSliceReferenceSize, inspect2Value.Length);
            Assert.IsTrue(inspect1Value.Zip(inspect2Value, (a, b) => a == b).All(b => b));
        }
예제 #2
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);
            }
        }
예제 #3
0
        public void BranchedOptionWire_Execute_BothSinksHaveCorrectValues()
        {
            DfirRoot       function    = DfirRoot.Create();
            FunctionalNode initialSome = CreateInt32SomeConstructor(function.BlockDiagram, 5);
            FunctionalNode inspect1    = new FunctionalNode(function.BlockDiagram, Signatures.InspectType),
                           inspect2    = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);

            Wire.Create(function.BlockDiagram, initialSome.OutputTerminals[0], inspect1.InputTerminals[0], inspect2.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspect1Value = executionInstance.GetLastValueFromInspectNode(inspect1),
            inspect2Value = executionInstance.GetLastValueFromInspectNode(inspect2);
            AssertByteArrayIsSomeInteger(inspect1Value, 5);
            AssertByteArrayIsSomeInteger(inspect2Value, 5);
        }
예제 #4
0
        public void UnwrapOptionTunnelWithSomeInputAndYieldingFrameInterior_Execute_FrameExecutes()
        {
            DfirRoot       function = DfirRoot.Create();
            FunctionalNode some     = new FunctionalNode(function.BlockDiagram, Signatures.SomeConstructorType);

            ConnectConstantToInputTerminal(some.InputTerminals[0], NITypes.Int32, 5, false);
            Frame frame = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOptionTunnel = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, some.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            BorrowTunnel borrowTunnel = CreateBorrowTunnel(frame, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(borrowTunnel.InputTerminals[0], NITypes.Int32, 0, true);
            FunctionalNode assign    = new FunctionalNode(frame.Diagram, Signatures.AssignType);
            var            yieldNode = new FunctionalNode(frame.Diagram, Signatures.YieldType);

            Wire.Create(frame.Diagram, borrowTunnel.OutputTerminals[0], yieldNode.InputTerminals[0]);
            Wire.Create(frame.Diagram, yieldNode.OutputTerminals[0], assign.InputTerminals[0]);
            Wire.Create(frame.Diagram, unwrapOptionTunnel.OutputTerminals[0], assign.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(borrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] finalValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(finalValue, 5);
        }
예제 #5
0
        public void SumItemsFromRangeIterator_Execute_CorrectFinalResult()
        {
            DfirRoot            function        = DfirRoot.Create();
            Loop                loop            = new Loop(function.BlockDiagram);
            LoopConditionTunnel conditionTunnel = CreateLoopConditionTunnel(loop);
            IterateTunnel       iterateTunnel   = CreateIterateTunnel(loop);
            FunctionalNode      range           = new FunctionalNode(function.BlockDiagram, Signatures.RangeType);
            Wire                rangeWire       = Wire.Create(function.BlockDiagram, range.OutputTerminals[0], iterateTunnel.InputTerminals[0]);

            rangeWire.SetWireBeginsMutableVariable(true);
            Constant       lowConstant        = ConnectConstantToInputTerminal(range.InputTerminals[0], NITypes.Int32, 0, false);
            Constant       highConstant       = ConnectConstantToInputTerminal(range.InputTerminals[1], NITypes.Int32, 10, false);
            BorrowTunnel   borrow             = CreateBorrowTunnel(loop, BorrowMode.Mutable);
            Constant       accumulateConstant = ConnectConstantToInputTerminal(borrow.InputTerminals[0], NITypes.Int32, 0, true);
            FunctionalNode accumulateAdd      = new FunctionalNode(loop.Diagram, Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(loop.Diagram, borrow.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(loop.Diagram, iterateTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(borrow.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 45);
        }
예제 #6
0
        public void FunctionWithTwoI32sExchanged_Execute_CorrectFinalValues()
        {
            DfirRoot       function       = DfirRoot.Create();
            FunctionalNode exchangeValues = new FunctionalNode(function.BlockDiagram, Signatures.ExchangeValuesType);
            FunctionalNode inspect1       = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[0]),
                           inspect2       = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[1]);
            Constant value1 = ConnectConstantToInputTerminal(exchangeValues.InputTerminals[0], NITypes.Int32, 1, true),
                     value2 = ConnectConstantToInputTerminal(exchangeValues.InputTerminals[1], NITypes.Int32, 2, true);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue1 = executionInstance.GetLastValueFromInspectNode(inspect1),
            inspectValue2 = executionInstance.GetLastValueFromInspectNode(inspect2);
            AssertByteArrayIsInt32(inspectValue1, 2);
            AssertByteArrayIsInt32(inspectValue2, 1);
        }
예제 #7
0
        public void InitializeVectorAndSumWithSliceIterator_Execute_CorrectSumValue()
        {
            DfirRoot       function         = DfirRoot.Create();
            FunctionalNode initializeVector = CreateInitializeVectorWithIntegerConstants(function.BlockDiagram, 4, 4);
            FunctionalNode vectorToSlice    = new FunctionalNode(function.BlockDiagram, Signatures.VectorToSliceType);

            Wire.Create(function.BlockDiagram, initializeVector.OutputTerminals[0], vectorToSlice.InputTerminals[0]);
            FunctionalNode sliceToIterator = new FunctionalNode(function.BlockDiagram, Signatures.SliceToIteratorType);

            Wire.Create(function.BlockDiagram, vectorToSlice.OutputTerminals[0], sliceToIterator.InputTerminals[0]);
            Loop loop = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(loop);
            IterateTunnel iterateTunnel = CreateIterateTunnel(loop);
            BorrowTunnel  borrowTunnel  = CreateBorrowTunnel(loop, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(borrowTunnel.InputTerminals[0], NITypes.Int32, 0, true);
            Wire.Create(function.BlockDiagram, sliceToIterator.OutputTerminals[0], iterateTunnel.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            FunctionalNode accumulateAdd = new FunctionalNode(loop.Diagrams[0], Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(loop.Diagrams[0], borrowTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(loop.Diagrams[0], iterateTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspectNode = ConnectInspectToOutputTerminal(borrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspectNode);
            AssertByteArrayIsInt32(inspectValue, 16);
        }
예제 #8
0
        protected void TestPrimitiveOperation(
            NIType operationSignature,
            object leftValue,
            object rightValue,
            NIType inputType,
            bool mutating,
            Action <byte[]> testExpectedValue)
        {
            DfirRoot       function          = DfirRoot.Create();
            FunctionalNode functionNode      = new FunctionalNode(function.BlockDiagram, operationSignature);
            Constant       leftValueConstant = ConnectConstantToInputTerminal(functionNode.InputTerminals[0], inputType, leftValue, mutating);
            int            lastIndex         = 2;

            if (rightValue != null)
            {
                Constant rightValueConstant = ConnectConstantToInputTerminal(functionNode.InputTerminals[1], inputType, rightValue, false);
            }
            else
            {
                lastIndex = 1;
            }
            FunctionalNode inspect = ConnectInspectToOutputTerminal(mutating
                ? functionNode.OutputTerminals[0]
                : functionNode.OutputTerminals[lastIndex]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            testExpectedValue(inspectValue);
        }
예제 #9
0
        private byte[] CreateAndExecuteFunctionWithConstantAndInspect(NIType constantType, object constantValue)
        {
            DfirRoot              function          = DfirRoot.Create();
            FunctionalNode        inspect           = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            Constant              constant          = ConnectConstantToInputTerminal(inspect.InputTerminals[0], constantType, constantValue, false);
            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            return(executionInstance.GetLastValueFromInspectNode(inspect));
        }
예제 #10
0
        public void InitializeVectorAndSliceIndexWithNegativeIndex_Execute_NoElementValueReturned()
        {
            const int elementValue = 5;
            var       tuple        = CreateInitializeVectorAndSliceIndexFunction(elementValue, -1);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(tuple.Item1);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(tuple.Item2);
            AssertByteArrayIsInt32(inspectValue, 0);
        }
        public void OptionPatternStructureWithOutputTunnelAndNoneValueWiredToSelector_Execute_CorrectValueFromOutputTunnel()
        {
            DfirRoot function = CreateOptionPatternStructureWithOutputTunnelAndInspect(false, 0, 1);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            var inspectNode = function.BlockDiagram.Nodes.OfType <FunctionalNode>().Where(f => f.Signature == Signatures.InspectType).First();

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspectNode);
            AssertByteArrayIsInt32(inspectValue, 1);
        }
예제 #12
0
        public void BuildTupleAndDecomposeTupleAsMove_Execute_CorrectElementValues()
        {
            DfirRoot       function   = DfirRoot.Create();
            BuildTupleNode buildTuple = new BuildTupleNode(function.BlockDiagram, 2);

            ConnectConstantToInputTerminal(buildTuple.InputTerminals[0], NITypes.Int32, 1, false);
            ConnectConstantToInputTerminal(buildTuple.InputTerminals[1], NITypes.Boolean, true, false);
            var decomposeTuple = new DecomposeTupleNode(function.BlockDiagram, 2, DecomposeMode.Move);

            Wire.Create(function.BlockDiagram, buildTuple.OutputTerminals[0], decomposeTuple.InputTerminals[0]);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(decomposeTuple.OutputTerminals[0]),
                           inspect1 = ConnectInspectToOutputTerminal(decomposeTuple.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 1);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsBoolean(inspectValue, true);
        }
예제 #13
0
        public void StructConstructorIntoStructFieldAccessor_Execute_FieldValuesAccessed()
        {
            DfirRoot function = DfirRoot.Create();
            var      structConstructorNode = new StructConstructorNode(function.BlockDiagram, StructType);

            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[0], NITypes.Int32, 5, false);
            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[1], NITypes.Boolean, true, false);
            var structFieldAccessor = new StructFieldAccessorNode(function.BlockDiagram, new string[] { "_0", "_1" });

            Wire.Create(function.BlockDiagram, structConstructorNode.OutputTerminals[0], structFieldAccessor.StructInputTerminal);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[0]);
            FunctionalNode inspect1 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 5);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsBoolean(inspectValue, true);
        }
예제 #14
0
        public void VariantConstructorsWithValidFields_Execute_CorrectVariantValue()
        {
            DfirRoot function = DfirRoot.Create();
            var      variantConstructorNodeInt = new VariantConstructorNode(function.BlockDiagram, VariantType, 0);

            ConnectConstantToInputTerminal(variantConstructorNodeInt.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode inspectInt = ConnectInspectToOutputTerminal(variantConstructorNodeInt.VariantOutputTerminal);
            var            variantConstructorNodeBool = new VariantConstructorNode(function.BlockDiagram, VariantType, 1);

            ConnectConstantToInputTerminal(variantConstructorNodeBool.InputTerminals[0], NITypes.Boolean, true, false);
            FunctionalNode inspectBool = ConnectInspectToOutputTerminal(variantConstructorNodeBool.VariantOutputTerminal);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectIntValue = executionInstance.GetLastValueFromInspectNode(inspectInt);
            Assert.AreEqual((byte)0, inspectIntValue[0]);
            Assert.AreEqual(5, BitConverter.ToInt32(inspectIntValue, 1));
            byte[] inspectBoolValue = executionInstance.GetLastValueFromInspectNode(inspectBool);
            Assert.AreEqual((byte)1, inspectBoolValue[0]);
            Assert.AreEqual((byte)1, inspectBoolValue[1]);
        }
예제 #15
0
        public void NonPanickingUnwrapOptionIntoInspect_Execute_CorrectValue()
        {
            DfirRoot function     = DfirRoot.Create();
            var      unwrapOption = new FunctionalNode(function.BlockDiagram, Signatures.UnwrapOptionType);

            ConnectSomeOfIntegerToInputTerminal(unwrapOption.InputTerminals[0], 5, false);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(unwrapOption.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 5);
        }
예제 #16
0
        public void CreateYieldPromiseAndAwait_Execute_ExecutionFinishesAndYieldedValueReadFromInspect()
        {
            DfirRoot function  = DfirRoot.Create();
            var      yieldNode = new FunctionalNode(function.BlockDiagram, Signatures.YieldType);

            ConnectConstantToInputTerminal(yieldNode.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(yieldNode.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 5);
        }
예제 #17
0
        public void ExchangeValuesWithSomeAndNoneInput_Execute_CorrectFinalValues()
        {
            DfirRoot       function       = DfirRoot.Create();
            FunctionalNode exchangeValues = new FunctionalNode(function.BlockDiagram, Signatures.ExchangeValuesType);
            FunctionalNode some           = CreateInt32SomeConstructor(function.BlockDiagram, 5);
            Wire           someWire       = Wire.Create(function.BlockDiagram, some.OutputTerminals[0], exchangeValues.InputTerminals[0]);

            someWire.SetWireBeginsMutableVariable(true);
            FunctionalNode none     = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);
            Wire           noneWire = Wire.Create(function.BlockDiagram, none.OutputTerminals[0], exchangeValues.InputTerminals[1]);

            noneWire.SetWireBeginsMutableVariable(true);
            FunctionalNode noneInspect = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[0]);
            FunctionalNode someInspect = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] noneInspectValue = executionInstance.GetLastValueFromInspectNode(noneInspect);
            AssertByteArrayIsNoneInteger(noneInspectValue);
            byte[] someInspectValue = executionInstance.GetLastValueFromInspectNode(someInspect);
            AssertByteArrayIsSomeInteger(someInspectValue, 5);
        }
        public void OptionPatternStructureSelectorWiredToInspectOnSomeValueDiagram_Execute_CorrectValue()
        {
            DfirRoot function = DfirRoot.Create();
            OptionPatternStructure patternStructure = CreateOptionPatternStructureWithOptionValueWiredToSelector(function.BlockDiagram, 1);
            FunctionalNode         someInspectNode  = new FunctionalNode(patternStructure.Diagrams[0], Signatures.InspectType);

            Wire.Create(patternStructure.Diagrams[0], patternStructure.Selector.OutputTerminals[0], someInspectNode.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(someInspectNode);
            AssertByteArrayIsInt32(inspectValue, 1);
        }
예제 #19
0
        public void SelectReferenceWithFalseSelector_Execute_CorrectSelectedResult()
        {
            DfirRoot       function           = DfirRoot.Create();
            FunctionalNode selectReference    = new FunctionalNode(function.BlockDiagram, Signatures.SelectReferenceType);
            Constant       selectorConstant   = ConnectConstantToInputTerminal(selectReference.InputTerminals[0], NITypes.Boolean, false, false);
            Constant       trueValueConstant  = ConnectConstantToInputTerminal(selectReference.InputTerminals[1], NITypes.Int32, 1, false);
            Constant       falseValueConstant = ConnectConstantToInputTerminal(selectReference.InputTerminals[2], NITypes.Int32, 0, false);
            FunctionalNode inspect            = ConnectInspectToOutputTerminal(selectReference.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 0);
        }
예제 #20
0
        public void FunctionWithRangeWithInt32Inputs_Execute_CorrectRangeValue()
        {
            DfirRoot       function  = DfirRoot.Create();
            FunctionalNode range     = new FunctionalNode(function.BlockDiagram, Signatures.RangeType);
            Constant       lowValue  = ConnectConstantToInputTerminal(range.InputTerminals[0], NITypes.Int32, 0, false);
            Constant       highValue = ConnectConstantToInputTerminal(range.InputTerminals[1], NITypes.Int32, 10, false);
            FunctionalNode inspect   = ConnectInspectToOutputTerminal(range.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            Assert.AreEqual(8, inspectValue.Length);
            Assert.AreEqual(-1, BitConverter.ToInt32(inspectValue, 0));
            Assert.AreEqual(10, BitConverter.ToInt32(inspectValue, 4));
        }
예제 #21
0
        public void FunctionWithInt32AssignedToNewValue_Execute_CorrectFinalValue()
        {
            DfirRoot       function = DfirRoot.Create();
            FunctionalNode inspect  = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            FunctionalNode assign   = new FunctionalNode(function.BlockDiagram, Signatures.AssignType);

            Wire.Create(function.BlockDiagram, assign.OutputTerminals[0], inspect.InputTerminals[0]);
            Constant finalValue   = ConnectConstantToInputTerminal(assign.InputTerminals[1], NITypes.Int32, 2, false);
            Constant initialValue = ConnectConstantToInputTerminal(assign.InputTerminals[0], NITypes.Int32, true);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 2);
        }
예제 #22
0
        public void CreateSharedAndCloneAndDereferenceBothCopies_Execute_CorrectDereferencedValues()
        {
            DfirRoot       function     = DfirRoot.Create();
            FunctionalNode createShared = new FunctionalNode(function.BlockDiagram, Signatures.SharedCreateType);

            ConnectConstantToInputTerminal(createShared.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode createCopy = new FunctionalNode(function.BlockDiagram, Signatures.CreateCopyType);

            Wire.Create(function.BlockDiagram, createShared.OutputTerminals[0], createCopy.InputTerminals[0]);
            FunctionalNode getCellValue0 = new FunctionalNode(function.BlockDiagram, Signatures.SharedGetValueType),
                           getCellValue1 = new FunctionalNode(function.BlockDiagram, Signatures.SharedGetValueType);

            Wire.Create(function.BlockDiagram, createCopy.OutputTerminals[0], getCellValue0.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, createCopy.OutputTerminals[1], getCellValue1.InputTerminals[0]);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(getCellValue0.OutputTerminals[0]),
                           inspect1 = ConnectInspectToOutputTerminal(getCellValue1.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 5);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsInt32(inspectValue, 5);
        }
예제 #23
0
        public void AssignOptionValueToNoneValue_Execute_CorrectFinalValue()
        {
            DfirRoot       function = DfirRoot.Create();
            FunctionalNode assign, inspect;

            CreateAssignToSomeInt32ValueAndInspect(function.BlockDiagram, out assign, out inspect);
            FunctionalNode finalNone = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);

            Wire.Create(function.BlockDiagram, finalNone.OutputTerminals[0], assign.InputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsNoneInteger(inspectValue);
        }
예제 #24
0
        public void LoopWithOutputTunnelThatDoesNotExecute_Execute_TunnelOutputsNoneValue()
        {
            DfirRoot            function        = DfirRoot.Create();
            Loop                loop            = new Loop(function.BlockDiagram);
            LoopConditionTunnel conditionTunnel = CreateLoopConditionTunnel(loop);
            Constant            falseConstant   = ConnectConstantToInputTerminal(conditionTunnel.InputTerminals[0], NITypes.Boolean, false, false);
            Tunnel              outputTunnel    = CreateOutputTunnel(loop);

            ConnectConstantToInputTerminal(outputTunnel.InputTerminals[0], NITypes.Int32, false);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(outputTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsNoneInteger(inspectValue);
        }
예제 #25
0
        public void CreateCopyWithOptionValue_Execute_CopyHasCorrectValue()
        {
            DfirRoot       function   = DfirRoot.Create();
            FunctionalNode some       = CreateInt32SomeConstructor(function.BlockDiagram, 5);
            FunctionalNode createCopy = new FunctionalNode(function.BlockDiagram, Signatures.CreateCopyType);

            Wire.Create(function.BlockDiagram, some.OutputTerminals[0], createCopy.InputTerminals[0]);
            FunctionalNode inspect = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);

            Wire.Create(function.BlockDiagram, createCopy.OutputTerminals[1], inspect.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsSomeInteger(inspectValue, 5);
        }
예제 #26
0
        public void ReborrowMutableReferenceAsImmutableAndOutput_Execute_CorrectValue()
        {
            DfirRoot function      = DfirRoot.Create();
            var      mutableBorrow = new ExplicitBorrowNode(function.BlockDiagram, BorrowMode.Mutable, 1, true, true);

            ConnectConstantToInputTerminal(mutableBorrow.InputTerminals[0], NITypes.Int32, 5, true);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(mutableBorrow.OutputTerminals[0]);

            // set mutable reference wire to mutable so that it gets a local allocation
            mutableBorrow.OutputTerminals[0].GetWireIfConnected().SetWireBeginsMutableVariable(true);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 5);
        }
예제 #27
0
        public void FillVectorEnoughToGrowItThenRemoveAllElements_Execute_AllElementsPreservedAndRemoved()
        {
            DfirRoot function     = DfirRoot.Create();
            var      createVector = new FunctionalNode(function.BlockDiagram, Signatures.VectorCreateType);
            Loop     firstLoop    = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(firstLoop);
            BorrowTunnel firstLoopBorrowTunnel = CreateBorrowTunnel(firstLoop, BorrowMode.Mutable);

            Wire.Create(function.BlockDiagram, createVector.OutputTerminals[0], firstLoopBorrowTunnel.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            IterateTunnel iterateTunnel  = CreateRangeAndIterateTunnel(firstLoop, 1, 7);
            var           appendToVector = new FunctionalNode(firstLoop.Diagram, Signatures.VectorAppendType);

            Wire.Create(firstLoop.Diagram, firstLoopBorrowTunnel.OutputTerminals[0], appendToVector.InputTerminals[0]);
            Wire.Create(firstLoop.Diagram, iterateTunnel.OutputTerminals[0], appendToVector.InputTerminals[1]);
            Loop secondLoop = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(secondLoop);
            BorrowTunnel secondLoopBorrowTunnel = CreateBorrowTunnel(secondLoop, BorrowMode.Mutable);

            Wire.Create(function.BlockDiagram, firstLoopBorrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0], secondLoopBorrowTunnel.InputTerminals[0]);
            CreateRangeAndIterateTunnel(secondLoop, 1, 7);
            var removeLastFromVector = new FunctionalNode(secondLoop.Diagram, Signatures.VectorRemoveLastType);

            Wire.Create(secondLoop.Diagram, secondLoopBorrowTunnel.OutputTerminals[0], removeLastFromVector.InputTerminals[0]);
            BorrowTunnel resultBorrowTunnel = CreateBorrowTunnel(secondLoop, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(resultBorrowTunnel.InputTerminals[0], NITypes.Int32, 0, true);
            Frame unwrapFrame = Frame.Create(secondLoop.Diagram);
            UnwrapOptionTunnel unwrapTunnel = CreateUnwrapOptionTunnel(unwrapFrame);

            Wire.Create(secondLoop.Diagram, removeLastFromVector.OutputTerminals[1], unwrapTunnel.InputTerminals[0]);
            Tunnel inputTunnel = CreateInputTunnel(unwrapFrame);

            Wire.Create(secondLoop.Diagram, resultBorrowTunnel.OutputTerminals[0], inputTunnel.InputTerminals[0]);
            var accumulateAdd = new FunctionalNode(unwrapFrame.Diagram, Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(unwrapFrame.Diagram, inputTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(unwrapFrame.Diagram, unwrapTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(resultBorrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 21);
        }
예제 #28
0
        public void UnwrapOptionTunnelWithSomeInputAndOutputTunnel_Execute_OutputTunnelOutputsSomeValue()
        {
            DfirRoot           function           = DfirRoot.Create();
            FunctionalNode     some               = CreateInt32SomeConstructor(function.BlockDiagram, 5);
            Frame              frame              = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOptionTunnel = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, some.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            Tunnel         outputTunnel = CreateOutputTunnel(frame);
            Constant       intConstant  = ConnectConstantToInputTerminal(outputTunnel.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode inspect      = ConnectInspectToOutputTerminal(outputTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] finalValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsSomeInteger(finalValue, 5);
        }
예제 #29
0
        public void CreateNotifierPairSetNotifierValueAndGetNotifierValue_Execute_ExecutionFinishesAndSomeValueReadFromInspect()
        {
            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]);
            var            setNotifierValue = new FunctionalNode(function.BlockDiagram, Signatures.SetNotifierValueType);

            Wire.Create(function.BlockDiagram, createNotifierPair.OutputTerminals[1], setNotifierValue.InputTerminals[0]);
            ConnectConstantToInputTerminal(setNotifierValue.InputTerminals[1], NITypes.Int32, 5, false);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsSomeInteger(inspectValue, 5);
        }
예제 #30
0
        public void LoopWithOutputTunnelThatExecutes_Execute_TunnelOutputsSomeValue()
        {
            DfirRoot            function        = DfirRoot.Create();
            Loop                loop            = new Loop(function.BlockDiagram);
            LoopConditionTunnel conditionTunnel = CreateLoopConditionTunnel(loop);
            Constant            trueConstant    = ConnectConstantToInputTerminal(conditionTunnel.InputTerminals[0], NITypes.Boolean, true, false);
            FunctionalNode      assign          = new FunctionalNode(loop.Diagram, Signatures.AssignType);

            Wire.Create(loop.Diagram, conditionTunnel.OutputTerminals[0], assign.InputTerminals[0]);
            Constant       falseConstant = ConnectConstantToInputTerminal(assign.InputTerminals[1], NITypes.Boolean, false, false);
            Tunnel         outputTunnel  = CreateOutputTunnel(loop);
            Constant       intConstant   = ConnectConstantToInputTerminal(outputTunnel.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode inspect       = ConnectInspectToOutputTerminal(outputTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsSomeInteger(inspectValue, 5);
        }