Пример #1
0
        public Interpreter(IGenericHelper genericHelper, IFunctionHelper functionHelper,
                           IIntegerHelper integerHelper, IRealHelper realHelper,
                           IBooleanHelper booleanHelper, ISetHelper setHelper,
                           IElementHelper elementHelper, IStringHelper stringHelper,
                           IGraphHelper graphHelper, bool catchExceptions)
        {
            _catchExceptions = catchExceptions;
            _exceptions      = new ComponentException();
            _functionHelper  = functionHelper;

            _integerHelper = integerHelper;
            _integerHelper.SetInterpreter(this);

            _realHelper = realHelper;
            _realHelper.SetInterpreter(this);

            _booleanHelper = booleanHelper;
            _booleanHelper.SetInterpreter(this);

            _genericHelper = genericHelper;
            _genericHelper.SetInterpreter(this);

            _setHelper = setHelper;
            _setHelper.SetInterpreter(this);

            _elementHelper = elementHelper;
            _elementHelper.SetInterpreter(this);

            _stringHelper = stringHelper;
            _stringHelper.SetInterpreter(this);

            _graphHelper = graphHelper;
            _graphHelper.SetInterpreter(this);
        }
Пример #2
0
        public static Interpreter GetIntepreterOnlyWith(IBooleanHelper booleanHelper)
        {
            IFunctionHelper functionHelper = Substitute.For <IFunctionHelper>();
            IIntegerHelper  integerHelper  = Substitute.For <IIntegerHelper>();
            IRealHelper     realHelper     = Substitute.For <IRealHelper>();
            IGenericHelper  genericHelper  = Substitute.For <IGenericHelper>();
            ISetHelper      setHelper      = Substitute.For <ISetHelper>();
            IElementHelper  elemHelper     = Substitute.For <IElementHelper>();
            IStringHelper   stringHelper   = Substitute.For <IStringHelper>();
            IGraphHelper    graphHelper    = Substitute.For <IGraphHelper>();

            return(new Interpreter(genericHelper, functionHelper, integerHelper, realHelper, booleanHelper, setHelper, elemHelper, stringHelper, graphHelper, false));
        }
Пример #3
0
        public void Dispatch_IntegerLiteralAndObjectListAndIntegerType_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            IntegerLiteralExpression input1  = new IntegerLiteralExpression("", 0, 0);
            IIntegerHelper           ihelper = Substitute.For <IIntegerHelper>();
            Interpreter   interpreter        = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object> res = null;

            ihelper.LiteralInteger(Arg.Any <IntegerLiteralExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.Dispatch(input1, expected, TypeEnum.Integer);

            res.Should().BeEquivalentTo(expected);
        }
Пример #4
0
        public void Dispatch_IntegerLiteralAndObjectListAndIntegerType_CorrectValueReturned()
        {
            int expected = 17;
            IntegerLiteralExpression input1 = new IntegerLiteralExpression("", 0, 0);
            List <Object>            input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IIntegerHelper ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.LiteralInteger(Arg.Any <IntegerLiteralExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            int res = (int)interpreter.Dispatch(input1, input2, TypeEnum.Integer);

            Assert.AreEqual(expected, res);
        }
        public void DispatchInteger_SubtractionAndObjectList_CorrectListPassed()
        {
            List <Object> expected = new List <Object>()
            {
                23, 2.334, null
            };
            SubtractionExpression input1      = new SubtractionExpression(null, null, 0, 0);
            IIntegerHelper        ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter           interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            List <Object>         res         = null;

            ihelper.SubtractionInteger(Arg.Any <SubtractionExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.DispatchInt(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }
        public void DispatchInteger_AdditionAndObjectList_CorrectValueReturned()
        {
            int expected = 17;
            AdditionExpression input1 = new AdditionExpression(null, null, 0, 0);
            List <Object>      input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IIntegerHelper ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(ihelper);

            ihelper.AdditionInteger(Arg.Any <AdditionExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            int res = interpreter.DispatchInt(input1, input2);

            Assert.AreEqual(expected, res);
        }
        public void DispatchInteger_AdditionAndObjectList_CorrectAdditionExprPassed()
        {
            AdditionExpression expected = new AdditionExpression(null, null, 0, 0);
            AdditionExpression input1   = expected;
            List <Object>      input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IIntegerHelper     ihelper     = Substitute.For <IIntegerHelper>();
            Interpreter        interpreter = Utilities.GetIntepreterOnlyWith(ihelper);
            AdditionExpression res         = null;

            ihelper.AdditionInteger(Arg.Do <AdditionExpression>(x => res = x), Arg.Any <List <Object> >());

            interpreter.DispatchInt(input1, input2);

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