// 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 = "";
            }
        }
Ejemplo n.º 2
0
        public void divideByZeroExceptionTest(int x, int y)
        {
            var ex = Assert.Throws <DivideByZeroException>(() => CalculatorMethods.Quotient(x, y));

            Assert.AreEqual("Error", ex.Message);
        }
Ejemplo n.º 3
0
        public void QuotientTest(double a, double b, double expected)
        {
            var result = CalculatorMethods.Quotient(a, b);

            Assert.AreEqual(expected, result);
        }