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)); }
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)); }
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); }
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); }
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); }
private static bool EvaluateAndOperator(object left, object right) { IExpression expression = new AndExpression(new ConstantExpression(left), new ConstantExpression(right)); return((bool)expression.Evaluate(null)); }