Exemple #1
0
        public void backSpaceTest(string expr, string expected)
        {
            DataCollector DC = new DataCollector();

            DC.SetExpr(expr);

            DC.BackSpaceExpression();

            Assert.Equal(expected, DC.GetExpr());
        }
Exemple #2
0
        public void addTest(string expr, string add, string expected)
        {
            DataCollector DC = new DataCollector();

            DC.SetExpr(expr);

            DC.ChangeState();

            DC.AddStringExpression(add);

            Assert.Equal(expected, DC.GetExpr());
        }
        private void EvalBtn_Click(object sender, EventArgs e)
        {
            if (data.GetExpr().Equals(""))
            {
                MessageBox.Show("Expression Empty");
            }
            else
            {
                try
                {
                    if (data.GetStateAnswer())
                    {
                        data.SetExpr(Parser.ChangeVariable("ans", data.GetAnswer(), data.GetExpr()));
                    }
                    double holder = EvalBtn.GetResultEvaluation(data.GetExpr());
                    data.ChangeAnswer(holder);
                    ChangeText();
                    data.SetExpr(holder.ToString());
                }
                catch (MathErrorException error)
                {
                    data.SetExpr("0");
                    data.ChangeAnswer(0);
                    data.ChangeState();

                    MessageBox.Show(error.errorMessage(), "Arithmetic Error"); // first argument : the error message, the second argument : the error header message
                    ChangeText();
                }
                catch (SyntaxErrorException error)
                {
                    data.SetExpr("0");
                    data.ChangeAnswer(0);
                    data.ChangeState();

                    MessageBox.Show(error.errorMessage(), "Syntax Error"); // first argument : the error message, the second argument : the error header message
                    ChangeText();
                }
            }
        }