public void TestOrExpressionRightFalse() { // Create epression with && operator with left as true and right as false bool leftBool = true; bool rightBool = false; Expression leftExpr = new ExpressionValue(leftBool); Expression rightExpr = new ExpressionValue(rightBool); ExpressionOr orExpr = new ExpressionOr(leftExpr, rightExpr); // Left and right operands should be boolean Assert.AreEqual(leftBool, leftExpr.Evaluate()); Assert.AreEqual(rightBool, rightExpr.Evaluate()); // Result should be false Assert.AreEqual(leftBool || rightBool, orExpr.Evaluate()); }
public void TestDivisionExpression() { // Create expression with + operator int leftInt = 4; int rightInt = 2; Expression leftExpr = new ExpressionValue(leftInt); Expression rightExpr = new ExpressionValue(rightInt); ExpressionDiv addExpr = new ExpressionDiv(leftExpr, rightExpr); // Left and right operands should be integers Assert.AreEqual(leftInt, leftExpr.Evaluate()); Assert.AreEqual(rightInt, rightExpr.Evaluate()); // Sum should be the sum of the left and right operands Assert.AreEqual(leftInt / rightInt, addExpr.Evaluate()); }
public void TestAndExpressionBothTrue() { // Create epression with && operator with left and right as true bool leftBool = true; bool rightBool = true; Expression leftExpr = new ExpressionValue(leftBool); Expression rightExpr = new ExpressionValue(rightBool); ExpressionAnd andExpr = new ExpressionAnd(leftExpr, rightExpr); // Left and right operands should be boolean Assert.AreEqual(leftBool, leftExpr.Evaluate()); Assert.AreEqual(rightBool, rightExpr.Evaluate()); // Result should be true Assert.AreEqual(leftBool && rightBool, andExpr.Evaluate()); }