public void DispatchBool_ReturnsCorrect_Indentifier(bool expected)
        {
            var            node        = GetIdentifierExp();
            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);

            boolHelper.Identifier <bool>(Arg.Any <IdentifierExpression>(), Arg.Any <List <object> >())
            .Returns(expected);

            bool res = interpreter.DispatchBoolean(node, new List <Object>());

            Assert.AreEqual(res, expected);
        }
Beispiel #2
0
 public Set DispatchSet(ExpressionNode node, List <Object> parameters)
 {
     return(node switch
     {
         SetExpression e => _setHelper.SetExpression(e, parameters),
         UnionExpression e => _setHelper.UnionSet(e, parameters),
         IntersectionExpression e => _setHelper.IntersectionSet(e, parameters),
         SubtractionExpression e => _setHelper.SubtractionSet(e, parameters),
         IdentifierExpression e => _genericHelper.Identifier <Set>(e, parameters),
         FunctionCallExpression e => _genericHelper.FunctionCall <Set>(e, parameters),
         VerticesGraphField e => _setHelper.VerticesField(e, parameters),
         EdgesGraphField e => _setHelper.EdgesField(e, parameters),
         EmptySetLiteralExpression e => _setHelper.EmptySetLiteral(e, parameters),
         _ => throw new UnimplementedInterpreterException(node, "DispatctSet")
     });
        public void DispatchBool_Identifier_PassParametersDown(object o)
        {
            var parameters = GetParameterList();
            var node       = GetIdentifierExp();

            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);
            List <object>  res         = null;

            boolHelper.Identifier <bool>(Arg.Any <IdentifierExpression>(), Arg.Do <List <object> >(x => res = x))
            .Returns(true);

            interpreter.DispatchBoolean(node, parameters.ToList());

            res.Should().BeEquivalentTo(parameters);
        }
        public void DispatchBool_Identifier_PassNodeDown()
        {
            var parameters = GetParameterList();
            var node       = GetIdentifierExp();
            var expected   = node;

            IGenericHelper boolHelper  = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(boolHelper);
            Node           res         = null;

            boolHelper.Identifier <bool>(Arg.Do <IdentifierExpression>(x => res = x), Arg.Any <List <object> >())
            .Returns(true);
            interpreter.DispatchBoolean(node, parameters);

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

            ihelper.Identifier <int>(Arg.Any <IdentifierExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.DispatchInt(input1, expected);

            res.Should().BeEquivalentTo(expected);
        }
        public void DispatchReal_IdentifierAndObjectList_CorrectValueReturned()
        {
            double expected             = 17;
            IdentifierExpression input1 = new IdentifierExpression(null, 0, 0);
            List <Object>        input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper rhelper     = Substitute.For <IGenericHelper>();
            Interpreter    interpreter = Utilities.GetIntepreterOnlyWith(rhelper);

            rhelper.Identifier <double>(Arg.Any <IdentifierExpression>(), Arg.Any <List <Object> >()).Returns(expected);

            double res = interpreter.DispatchReal(input1, input2);

            Assert.AreEqual(expected, res);
        }
        public void DispatchReal_IdentifierAndObjectList_CorrectIdentifierExprPassed()
        {
            IdentifierExpression expected = new IdentifierExpression(null, 0, 0);
            IdentifierExpression input1   = expected;
            List <Object>        input2   = new List <Object>()
            {
                23, 2.334, null
            };
            IGenericHelper       rhelper     = Substitute.For <IGenericHelper>();
            Interpreter          interpreter = Utilities.GetIntepreterOnlyWith(rhelper);
            IdentifierExpression res         = null;

            rhelper.Identifier <double>(Arg.Do <IdentifierExpression>(x => res = x), Arg.Any <List <Object> >());

            interpreter.DispatchReal(input1, input2);

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