Пример #1
0
        public void Sum()
        {
            var actual   = calc.Sum(new ComplexNum(4, -9), new ComplexNum(-5, 12));
            var expected = new ComplexNum(-1, 3);

            Assert.AreEqual(expected, actual);
        }
        private void equalsButton_Click(object sender, RoutedEventArgs e)
        {
            ComplexCalculator.Operations calc = new ComplexCalculator.Operations();
            if (string.IsNullOrWhiteSpace(imaginaryPartInput.Text))
            {
                num2 = new ComplexNum(Convert.ToDouble(realPartInput.Text), 0);
            }
            else
            {
                num2 = new ComplexNum(Convert.ToDouble(realPartInput.Text), Convert.ToDouble(imaginaryPartInput.Text));
            }
            switch (znak)
            {
            case '+': result = calc.Sum(num1, num2);
                break;

            case '-': result = calc.Dif(num1, num2);
                break;

            case '*': result = calc.Prod(num1, num2);
                break;

            case '/': result = calc.Div(num1, num2);
                break;

            case 'x': result = calc.Pow(num1, (int)num2.real);
                break;
            }
            imaginaryPartInput.Clear();
            realPartInput.Clear();
            string a = "";

            if (result.imaginary < 0)
            {
                a = result.real.ToString();
            }
            else
            {
                a = result.real.ToString() + "+";
            }
            string b      = result.imaginary.ToString() + 'i';
            string output = a + b;

            resultOutputWindow.Text = output;
        }