示例#1
0
        public void ParseTest1()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("(50)");
            Assert.AreEqual(ex.Parse(), 50);
            ex = new ExpressionModule("(+50)");
            Assert.AreEqual(ex.Parse(), 50);
            ex = new ExpressionModule("(-50)");
            Assert.AreEqual(ex.Parse(), -50);
        }
示例#2
0
        public void ParseTest2()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("2+3");
            Assert.AreEqual(ex.Parse(), 5);
            ex = new ExpressionModule("3*3+3");
            Assert.AreEqual(ex.Parse(), 12);
            ex = new ExpressionModule("(2*2)+2");
            Assert.AreEqual(ex.Parse(), 6);
            ex = new ExpressionModule("(2+2)*2");
            Assert.AreEqual(ex.Parse(), 8);
        }
示例#3
0
        public void ParseTest3()
        {
            ExpressionModule ex;

            ex = new ExpressionModule("2+-3");
            Assert.AreEqual(ex.Parse(), -1);
            ex = new ExpressionModule("3*3--3");
            Assert.AreEqual(ex.Parse(), 12);
            ex = new ExpressionModule("(2*-2)+2");
            Assert.AreEqual(ex.Parse(), -2);
            ex = new ExpressionModule("-(2+2)*2");
            Assert.AreEqual(ex.Parse(), -8);
        }
示例#4
0
        private void SolveButton_OnClick(object sender, RoutedEventArgs e)
        {
            ExpressionModule expr = new ExpressionModule(InputTextBox.Text);

            try
            {
                AnswerText.Text = "Ответ: " + expr.Parse();
            }
            catch (Exception exception)
            {
                AnswerText.Text = String.Format("Ошибка {0}:\n{1}", exception.GetType(), exception.Message);
            }
        }