public void TestFail() { string expr = "1,2,3,+,-";//2,2,+,3,-,2,+"; RPN rpn = new RPN(); Assert.AreEqual(-4, rpn.calculate(expr)); }
public void TestCalculate() { string expr = "2,2,+,3,-"; RPN rpn = new RPN(); Assert.AreEqual(12, rpn.calculate(expr)); }
public void TestPerformoperation() { RPN rpn = new RPN(); string operators = "*"; string operand1 = "3"; string operand2 = "6"; Assert.AreEqual(18, rpn.PerformOperation(operators, operand1, operand2)); }
public void TestStringForCommas() { try { RPN rpn = new RPN(); string expr = "2,2*"; Assert.Ignore(rpn.calculate(expr).ToString()); } catch (Exception exp) { Assert.AreEqual("Expression should have at least two commas", exp.Message); } }
public void TestStack() { RPN rpn = new RPN(); string expr = "2,2,*,5"; string[] exprArray = new string[expr.Length]; exprArray = expr.Split(','); string[] exprArrayReverse = exprArray.Reverse().ToArray(); Stack <string> stack = rpn.GetStackFromArray(exprArray); string[] exprArrayReverse2 = stack.ToArray(); Assert.AreEqual(exprArrayReverse2, exprArrayReverse); }
private void btnEvaluate_Click(object sender, RoutedEventArgs e) { RPN rpn = new RPN(txtlInput.Text); try { txtAnswer.Text = rpn.CalculateExpression().ToString(); } catch (System.Exception ex) { if (ex is System.InvalidCastException) { txtAnswer.Text = ex.Message; } if (ex is System.InvalidOperationException) { txtAnswer.Text = ex.Message; } if (ex is System.DivideByZeroException) { txtAnswer.Text = ex.Message; } } }
public void ThenTheResultShouldBeOnTheScreen(int p0) { RPN obj = new RPN(); Assert.AreEqual(p0, obj.calculate(expression)); }
static void Main(string[] args) { RPN rpn = new RPN(); rpn.calculate("2,2,+"); }