Exemple #1
0
        private void OneOperationCalculation(string designation)
        {
            double result, operand1, operand2;
            int    idx;

            while (inputtedOperations.Contains(designation))
            {
                idx      = inputtedOperations.IndexOf(designation);
                operand1 = inputtedValuesDouble[idx];
                operand2 = inputtedValuesDouble[idx + 1];

                result = OperationsContainer
                         .GetExecutionMethodByDesignation(designation)
                         ?.Invoke(operand1, operand2)
                         ?? throw new ApplicationException($"Operation {designation} not found.");
                result = Math.Round(result, GetMaxPrecision(operand1, operand2, result));

                inputtedOperations.RemoveAt(idx);
                inputtedValuesDouble.RemoveAt(idx + 1);
                inputtedValuesDouble[idx] = result;
            }
        }
Exemple #2
0
        private double SimpleCalculation(string input)
        {
            InitializeLists(input);

            foreach (OperationPrioriry priority in Enum.GetValues(typeof(OperationPrioriry)))
            {
                foreach (string designation in OperationsContainer.GetOperationsByPriority(priority))
                {
                    if (inputtedOperations.Contains(designation) && inputtedOperations.Count > 0)
                    {
                        OneOperationCalculation(designation);
                    }
                }
            }

            if (inputtedValuesDouble.Count == 1 && inputtedOperations.Count == 0)
            {
                return(inputtedValuesDouble[0]);
            }
            else
            {
                throw new ApplicationException("Extra values or operations were appeared somehow ¯\\_(ツ)_/¯");
            }
        }