예제 #1
0
        private IExpression RelationalExpression()
        {
            var expression = AdditiveExpression();

            while (lookAhead.Type == ExpressionTokenType.Less ||
                   lookAhead.Type == ExpressionTokenType.LessEqual ||
                   lookAhead.Type == ExpressionTokenType.Greater ||
                   lookAhead.Type == ExpressionTokenType.GreaterEqual)
            {
                var type = lookAhead.Type;
                NextToken();
                var rightOperand = AdditiveExpression();
                switch (type)
                {
                case ExpressionTokenType.Less:
                    expression = new LessThan(expression, rightOperand);
                    break;

                case ExpressionTokenType.LessEqual:
                    expression = new LessThanOrEquals(expression, rightOperand);
                    break;

                case ExpressionTokenType.Greater:
                    expression = new GreaterThan(expression, rightOperand);
                    break;

                case ExpressionTokenType.GreaterEqual:
                    expression = new GreaterThanOrEquals(expression, rightOperand);
                    break;
                }
            }
            return(expression);
        }
예제 #2
0
        public void Evaluate_LeftIsGreaterThanThanRight_ReturnsFalse()
        {
            var left  = new Integer(5000);
            var right = new Integer(3934);
            var expr  = new LessThanOrEquals(left, right);

            var result = expr.EvaluateWithData <bool>();

            Assert.False(result);
        }
예제 #3
0
        public void Evaluate_LeftIsEqualToRight_ReturnsTrue()
        {
            var left  = new Integer(3934);
            var right = new Integer(3934);
            var expr  = new LessThanOrEquals(left, right);

            var result = expr.EvaluateWithData <bool>();

            Assert.True(result);
        }
예제 #4
0
        public void ToString_IntegerComparison_ReturnsExpected()
        {
            var expr = new LessThanOrEquals(new Integer(3), new Integer(9));

            Assert.AreEqual("3 <= 9", expr.ToString());
        }