Exemple #1
0
        public void TestFail()
        {
            string expr = "1,2,3,+,-";//2,2,+,3,-,2,+";
            RPN    rpn  = new RPN();

            Assert.AreEqual(-4, rpn.calculate(expr));
        }
Exemple #2
0
        public void TestCalculate()
        {
            string expr = "2,2,+,3,-";
            RPN    rpn  = new RPN();

            Assert.AreEqual(12, rpn.calculate(expr));
        }
Exemple #3
0
        public void TestPerformoperation()
        {
            RPN    rpn       = new RPN();
            string operators = "*";
            string operand1  = "3";
            string operand2  = "6";

            Assert.AreEqual(18, rpn.PerformOperation(operators, operand1, operand2));
        }
Exemple #4
0
 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);
     }
 }
Exemple #5
0
        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);
        }
Exemple #6
0
        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;
                }
            }
        }
Exemple #7
0
        public void ThenTheResultShouldBeOnTheScreen(int p0)
        {
            RPN obj = new RPN();

            Assert.AreEqual(p0, obj.calculate(expression));
        }
Exemple #8
0
        static void Main(string[] args)
        {
            RPN rpn = new RPN();

            rpn.calculate("2,2,+");
        }