// Calculation initialize object handler - Runs the calculation and displays the result
        private void Calculate_Click(object sender, RoutedEventArgs e)
        {
            double num1   = double.Parse(x);
            double num2   = double.Parse(y);
            double output = 0;

            try
            {
                switch (symbol)
                {
                case ('+'):
                    output = CalculatorMethods.Add(num1, num2);
                    break;

                case ('-'):
                    output = CalculatorMethods.Subtract(num1, num2);
                    break;

                case ('/'):
                    output = CalculatorMethods.Quotient(num1, num2);

                    break;

                case ('x'):
                    output = CalculatorMethods.Product(num1, num2);
                    break;

                default:
                    x = "";
                    break;
                }
                displayBox.Text = output.ToString();
                x = output.ToString();
                y = "";
            }
            catch (DivideByZeroException ex)
            {
                displayBox.Text = ex.Message;
                x = "";
                y = "";
            }
        }
Example #2
0
        public void ProductTest(double a, double b, double expected)
        {
            var result = CalculatorMethods.Product(a, b);

            Assert.AreEqual(expected, result);
        }