public void DispatchReal_AbsoluteValueAndObjectList_CorrectValueReturned()
        {
            double expected = 17;
            AbsoluteValueExpression input1 = new AbsoluteValueExpression(null, 0, 0);
            List <Object>           input2 = new List <Object>()
            {
                23, 2.334, null
            };
            IRealHelper rhelper     = Substitute.For <IRealHelper>();
            Interpreter interpreter = Utilities.GetIntepreterOnlyWith(rhelper);

            rhelper.AbsoluteReal(Arg.Any <AbsoluteValueExpression>(), Arg.Any <List <Object> >()).Returns(expected);

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

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

            rhelper.AbsoluteReal(Arg.Any <AbsoluteValueExpression>(), Arg.Do <List <Object> >(x => res = x));

            interpreter.DispatchReal(input1, expected);

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

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

            interpreter.DispatchInt(input1, input2);

            res.Should().BeEquivalentTo(expected);
        }
        public TypeNode VisitAbsoluteValue(AbsoluteValueExpression n, List <TypeNode> parameterTypes)
        {
            TypeNode childType = GetType(n.Children[0], parameterTypes);

            if (childType.Type == TypeEnum.Real)
            {
                n.Type = TypeEnum.Real;
                return(childType);
            }
            else if (childType.Type == TypeEnum.Integer) //More types are added later, they all return integer
            {
                n.Type = TypeEnum.Integer;
                return(new TypeNode(TypeEnum.Integer, 0, 0));
            }
            else if (childType.Type == TypeEnum.Set)
            {
                n.Type = TypeEnum.Set;
                return(new TypeNode(TypeEnum.Integer, 0, 0));
            }
            else
            {
                throw new AbsoluteValueTypeException(n, childType.Type);
            }
        }
示例#5
0
        public double AbsoluteReal(AbsoluteValueExpression node, List <object> parameters)
        {
            double operand = _interpreter.DispatchReal(node.Children[0], parameters);

            return(Math.Abs(operand));
        }