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); }
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); }
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); }
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); } }