Beispiel #1
0
        public void FunctionInteger_FunctionNodeAndTwoConditionAndObjectList_CorrectExceptionThrown()
        {
            ConditionNode cn1    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            ConditionNode cn2    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            FunctionNode  input1 = new FunctionNode(new List <ConditionNode> {
                cn1, cn2
            }, "", null, null, 0, 0);
            List <Object> input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper fhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(fhelper);

            fhelper.Condition <int>(cn1, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, 17));
            fhelper.Condition <int>(cn2, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, 18));


            Assert.ThrowsException <ComponentException>(() => interpreter.Function <int>(input1, input2));
        }
Beispiel #2
0
        public void FunctionInteger_FunctionNodeAndTwoConditionsOneDefaultCaseAndObjectList_CorrectValueReturned(bool aValid, int a, bool bValid, int b, int expected)
        {
            ConditionNode cn1    = new ConditionNode(new BooleanLiteralExpression(true, 0, 0), null, 0, 0);
            ConditionNode cn2    = new ConditionNode(null, 0, 0);
            FunctionNode  input1 = new FunctionNode(new List <ConditionNode> {
                cn1, cn2
            }, "", null, null, 0, 0);
            List <Object> input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper fhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(fhelper);

            fhelper.Condition <int>(cn1, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(aValid, a));
            fhelper.Condition <int>(cn2, Arg.Any <List <Object> >()).Returns(new MatchPair <int>(bValid, b));

            int res = (int)interpreter.Function <int>(input1, input2);

            Assert.AreEqual(expected, res);
        }
Beispiel #3
0
        public void FunctionInteger_FunctionNodeAndObjectList_CorrectValueReturned()
        {
            int           expected = 17;
            FunctionNode  input1   = new FunctionNode("", new ConditionNode(null, 0, 0), null, null, 0, 0);
            List <Object> input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper ihelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.Condition <int>(Arg.Any <ConditionNode>(), Arg.Any <List <Object> >()).Returns(new MatchPair <int>(true, expected));

            int res = (int)interpreter.Function <int>(input1, input2);

            Assert.AreEqual(expected, res);
        }
Beispiel #4
0
        public void FunctionInteger_FunctionNodeAndObjectList_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            FunctionNode   input1      = new FunctionNode("", new ConditionNode(null, 0, 0), null, null, 0, 0);
            IGenericHelper ihelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object>  res         = null;

            ihelper.Condition <int>(Arg.Any <ConditionNode>(),
                                    Arg.Do <List <Object> >(x => res = x)).
            Returns(new MatchPair <int>(true, 1));

            interpreter.Function <int>(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }