コード例 #1
0
        public void TestRightTrueEvaluate()
        {
            var expression = new AndExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)false),
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)true),
                ExpressiveOptions.None);

            Assert.AreEqual(false, expression.Evaluate(null));
        }
コード例 #2
0
        public void TestBothTrueEvaluate()
        {
            var expression = new AndExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)true),
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)true),
                new Context(ExpressiveOptions.None));

            Assert.AreEqual(true, expression.Evaluate(null));
        }
コード例 #3
0
        public void GetAndEvaluateAndExpression()
        {
            AndExpression expression = AndExpression.Instance;

            Assert.IsNotNull(expression);

            Machine machine = new Machine();

            machine.Push(true);
            machine.Push(true);

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.IsTrue((bool)machine.Pop());
            Assert.AreEqual(0, machine.StackCount);

            machine.Push(true);
            machine.Push(false);

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.IsFalse((bool)machine.Pop());
            Assert.AreEqual(0, machine.StackCount);

            machine.Push(false);
            machine.Push(true);

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.IsFalse((bool)machine.Pop());
            Assert.AreEqual(0, machine.StackCount);

            machine.Push(false);
            machine.Push(false);

            expression.Evaluate(machine);

            Assert.AreEqual(1, machine.StackCount);
            Assert.IsFalse((bool)machine.Pop());
            Assert.AreEqual(0, machine.StackCount);
        }
コード例 #4
0
        private void DoTestEvaluate(IExpression a, IExpression b, bool expected)
        {
            // Arrange
            IExpression expression = new AndExpression(a, b);

            // Act
            bool result = expression.Evaluate(null);

            // Assert
            Assert.AreEqual(expected, result);
        }
コード例 #5
0
        public void TestShortCircuit()
        {
            var rightHandMock = new Mock <IExpression>();

            var expression = new AndExpression(
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)false),
                rightHandMock.Object,
                new Context(ExpressiveOptions.None));

            expression.Evaluate(null);

            rightHandMock.Verify(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()), Times.Never);
        }
コード例 #6
0
        private static bool EvaluateAndOperator(object left, object right)
        {
            IExpression expression = new AndExpression(new ConstantExpression(left), new ConstantExpression(right));

            return((bool)expression.Evaluate(null));
        }