private void SolveExpression(object sender, RoutedEventArgs e) { string expression = ExpressionBox.Text.TrimEnd(); if (!string.IsNullOrEmpty(expression)) { StringBuilder result = new StringBuilder(); try { result.Append(RomanExpressionSolver.Solve(expression)); ResultLabelText.FontSize = 70; ResultLabelText.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#8873CB")); ResultLabelText.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#250D71")); } catch (Exception ex) { result.Append(expression + " : " + ex.Message); ResultLabelText.FontSize = 16; ResultLabelText.Background = new SolidColorBrush(Colors.Red); ResultLabelText.Foreground = new SolidColorBrush(Colors.White); } ExpressionBox.Text = ""; ResultLabelText.Text = result.ToString(); LastExpressionText.Text = $"Last expression: {expression}"; ExpressionBox.Focus(); } }
public void Solve_ValidExpression_ReturnValue(string expression, string expected) { string result = RomanExpressionSolver.Solve(expression); Assert.AreEqual(expected, result); }