public void Test_ExpressionEvaluation() { var evaluate1 = "10 + 2 * 6"; var evaluate2 = "100 * 2 + 12"; var evaluate3 = "100 * (2 + 12)"; var evaluate4 = "100 * ( 2 + 12 ) / 14"; var actual = expressionEvaluation.Evaluate(evaluate1); var expected = 22; Assert.Equal(expected, actual); actual = expressionEvaluation.Evaluate(evaluate2); expected = 212; Assert.Equal(expected, actual); actual = expressionEvaluation.Evaluate(evaluate3); expected = 1400; Assert.Equal(expected, actual); //actual = expressionEvaluation.Evaluate(evaluate4); //expected = 100; //Assert.Equal(expected, actual); }
public void EvaluateTest() { Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(1 + 1)")); Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(4 - 2)")); Assert.AreEqual(8, ExpressionEvaluation.Evaluate("(2 ^ 3)")); Assert.AreEqual(4, ExpressionEvaluation.Evaluate("(2 * 2)")); Assert.AreEqual(1, ExpressionEvaluation.Evaluate("(2 / 2)")); Assert.AreEqual(10, ExpressionEvaluation.Evaluate("(1 + 1) * ((5/5) * 5))")); Assert.AreEqual(8, ExpressionEvaluation.Evaluate("(((4 / 2) + 2) + 4)")); Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(10 - 8)")); Assert.AreEqual(10, ExpressionEvaluation.Evaluate("(20 - 10)")); }