public void CalculateTest()
        {
            Plus calculator = new Plus();

            Assert.AreEqual(2, calculator.Calculate(1, 1));
            Assert.AreEqual(6.7, calculator.Calculate(5, 1.7));
            Assert.AreEqual(5, calculator.Calculate(0, 5));
        }
Esempio n. 2
0
        public void CalculateMultiTestStrong(double firstValue, double secondValue, double expected)
        {
            ITwoArgumentCalculator calculator = new Plus();
            double result = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, result);
        }
Esempio n. 3
0
        public void CalculateAdditionTestStrong(double firstValue, double secondValue, double expected)
        {
            ITwoArgumentsCalculator calculator = new Plus();
            double result = calculator.Calculate(13, 26);

            Assert.AreEqual(39, result);
        }
Esempio n. 4
0
        public void CalculateTest(double firstValue, double secondValue, double expected)
        {
            var calculator   = new Plus();
            var actualResult = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
Esempio n. 5
0
        public void CalculateTest()
        {
            ITwoArgumentsCalculator calcultor = new Plus();
            double actual = calcultor.Calculate(8, 2);

            Assert.AreEqual(10, actual);
        }
Esempio n. 6
0
        public static double Calculate(List <string> input)
        {
            Stack <double> numbers = new Stack <double>();
            double         value   = 0.0;

            for (int i = 0; i < input.Count; i++)
            {
                if (input[i][0] >= '0' && input[i][0] <= '9')
                {
                    numbers.Push(double.Parse(input[i]));
                }
                else if (OperationsCollection.Arithmetics.Contains(input[i]))
                {
                    IArithmeticOperator arithmeticOperator = null;
                    value = numbers.Pop();
                    double secValue = numbers.Pop();
                    double result   = 0.0;

                    switch (input[i])
                    {
                    case "+":
                        arithmeticOperator = new Plus();
                        result             = arithmeticOperator.Calculate(secValue, value);
                        break;

                    case "-":
                        arithmeticOperator = new Minus();
                        result             = (arithmeticOperator.Calculate(secValue, value));
                        break;

                    case "*":
                        arithmeticOperator = new Multiplication();
                        result             = arithmeticOperator.Calculate(secValue, value);
                        break;

                    case "/":
                        arithmeticOperator = new Division();
                        result             = arithmeticOperator.Calculate(secValue, value);
                        break;

                    case "%":
                        arithmeticOperator = new Remainder();
                        result             = arithmeticOperator.Calculate(secValue, value);
                        break;

                    case "^":
                        arithmeticOperator = new Pow();
                        result             = arithmeticOperator.Calculate(secValue, value);
                        break;;
                    }

                    numbers.Push(result);
                }
                else if (OperationsCollection.Functions.Contains(input[i]))
                {
                    IFunctionOperator functionOperator = null;
                    value = numbers.Pop();

                    switch (input[i])
                    {
                    case "sin":
                        functionOperator = new Sin();
                        break;

                    case "cos":
                        functionOperator = new Cos();
                        break;

                    case "tang":
                        functionOperator = new Tang();
                        break;

                    case "cotang":
                        functionOperator = new CoTang();
                        break;

                    case "sqrt":
                        functionOperator = new Sqrt();
                        break;

                    case "ln":
                        numbers.Push(Math.Log(value));
                        break;

                    case "log":
                        numbers.Push(Math.Log10(value));
                        break;
                    }

                    if (functionOperator != null)
                    {
                        double result = functionOperator.Calculate(value);

                        numbers.Push(result);
                    }
                }
            }

            return(numbers.Pop());
        }