Inheritance: System.Windows.Controls.Control
Esempio n. 1
0
        public void Check_Substract_Method_return_expected(double a, double b, double expected)
        {
            uut = new Calculator(a);
            double result = uut.Substact(b);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.EqualTo(expected));
                Assert.That(uut.Accumulator, Is.EqualTo(expected));
            });
        }
Esempio n. 2
0
        public void Check_Multiply_Method_return_expected(double a, double b, double expected)
        {
            uut = new Calculator(a);
            double result = uut.Multiply(b);

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.EqualTo(expected).Within(1E-1));
                Assert.That(uut.Accumulator, Is.EqualTo(expected).Within(1E-1));
            });
        }
Esempio n. 3
0
        public void Check_Devide_Method_return3_point_5()
        {
            uut = new Calculator(14);
            double result   = uut.Divide(4);
            double expected = 3.5;

            Assert.Multiple(() =>
            {
                Assert.That(result, Is.EqualTo(expected));
                Assert.That(uut.Accumulator, Is.EqualTo(expected));
            });
        }
Esempio n. 4
0
        public void UnitTestWithAllOperatorsReturns45_0()
        {
            // arrange
            var expression = "42+5.2-2*5.5/5";

            var corrector = new CalculatorProject.ExpressionCorrector();

            expression = corrector.Correct(expression);

            var calculator = new CalculatorProject.Calculator(
                new Parser(),
                new OperationPerformer());

            // act
            var actualResult = calculator.Compute(expression);

            // assert
            Assert.AreEqual(45.0, actualResult);
        }
Esempio n. 5
0
        public void UnitTestWithBracketsReturnsMin1_4()
        {
            // arrange
            var expression = "8.4+(6-7.8)-(9*(7-6)-1)";

            var corrector = new CalculatorProject.ExpressionCorrector();

            expression = corrector.Correct(expression);

            var calculator = new CalculatorProject.Calculator(
                new Parser(),
                new OperationPerformer());

            // act
            var actualResult = calculator.Compute(expression);

            // assert
            Assert.AreEqual(-1.4, actualResult);
        }
Esempio n. 6
0
 public void Check_Devide_Method_DividByZeroExc()
 {
     uut = new Calculator(14);
     Assert.Throws <DivideByZeroException>(() => uut.Divide(0));
 }
Esempio n. 7
0
 public void Check_Constructor_setting_Accumulator(double a, double expected)
 {
     uut = new Calculator(a);
     Assert.That(uut.Accumulator, Is.EqualTo(expected));
 }
Esempio n. 8
0
 public void OneTimeSetUp()
 {
     calculator = new Calculator();
 }
Esempio n. 9
0
        //private method to get the calculation results from the calculator
        private String getCalculationResult()
        {
            List <String> input = parseInput();

            //if the input is not empty
            if (input.Count != 0)
            {
                //if the user has specified they are using the simple calculator
                if (checkRefactoredCalculator.Checked == false)
                {
                    //if the input contains all 3 parts: (number operator number)
                    if (input.Count == 3)
                    {
                        //if the simpleCalculator has not been initiated yet
                        if (simpleCalculator == null)
                        {
                            simpleCalculator = new Calculator(input[0], input[2], input[1]); //call the constructor
                            simpleCalculator.calculate();                                    //calculate the result
                            return(simpleCalculator.getResult());                            //return the result
                        }
                        else
                        {
                            simpleCalculator.setLeft(input[0]);     //set the left operand
                            simpleCalculator.setOperator(input[1]); //set the operator
                            simpleCalculator.setRight(input[2]);    //set the right operand
                            simpleCalculator.calculate();           //calculate the result
                            return(simpleCalculator.getResult());   //return the result
                        }
                    }
                    //if the input only contains 2 parts: (number operator) or (operator number)
                    else if (input.Count == 2)
                    {
                        //if the simpleCalculator has not been initiated yet
                        if (simpleCalculator == null)
                        {
                            simpleCalculator = new Calculator(input[0], "", input[1]); //call the constructor
                            simpleCalculator.calculate();                              //calculate the result
                            return(simpleCalculator.getResult());                      //return the result
                        }
                        else
                        {
                            simpleCalculator.setLeft(input[0]);     //set the left operand
                            simpleCalculator.setOperator(input[1]); //set the operator
                            simpleCalculator.setRight("");          //set the right operand to be an empty string
                            simpleCalculator.calculate();           //calculate the result
                            return(simpleCalculator.getResult());   //return the result
                        }
                    }
                    //if the input only contains one part
                    else if (input.Count == 1)
                    {
                        /*
                         * //if the simpleCalculator has not been initiated yet
                         * if (simpleCalculator == null)
                         * {
                         *  simpleCalculator = new Calculator(input[0], "", "");    //call the constructor
                         *  simpleCalculator.calculate();   //calculate the result
                         *  return simpleCalculator.getResult();    //return the result
                         * }
                         * else
                         * {
                         *  simpleCalculator.setLeft(input[0]); //set the left operand
                         *  simpleCalculator.setOperator("");   //set the operator to be an empty string
                         *  simpleCalculator.setRight("");  //set the right operand to be an empty string
                         *  simpleCalculator.calculate();   //calculate the reuslt
                         *  return simpleCalculator.getResult();    //return the result
                         * }*/
                    }
                    //if the input is longer than the basic formula
                    else
                    {
                        //check for a failed scientific notation
                        foreach (String str in input)
                        {
                            if (str[str.Length - 1] == 'E')
                            {
                                for (int i = 0; i < str.Length - 1; i++)
                                {
                                    if (!Char.IsDigit(str[i]) && str[i] != '+' && str[i] != '-' && str[i] != '*' && str[i] != '/' && str[i] != '.')
                                    {
                                        return(String.Format("Error: \"{0}\" is not a number", str));
                                    }
                                }
                            }
                        }
                        return("Error: Too many arguments");
                    }
                }
                //if the user has specified they are using the refactored calculator
                else
                {
                    return(refactoredCalculator.calculate(input));   //return the result of the calculation
                }
            }

            return(calculatorDisplayBox.Text);
        }