Пример #1
0
        private Data GetData()
        {
            if (_inputParsedData.Length > 3 || _inputParsedData.Length < 2)
            {
                Revise.ArgumentException(Resource.InvalidNumberOfArguments);
            }

            if (_inputParsedData.Length == 3)
            {
                if (!double.TryParse(_inputParsedData[0], out double x))
                {
                    x = double.NaN;
                }

                if (!double.TryParse(_inputParsedData[2], out double y))
                {
                    y = double.NaN;
                }

                string operation = _inputParsedData[1];
                return(new Data(x, y, operation));
            }
            else
            {
                if (!double.TryParse(_inputParsedData[1], out double x))
                {
                    x = double.NaN;
                }

                string operation = _inputParsedData[0];
                return(new Data(x, double.NaN, operation));
            }
        }
Пример #2
0
        /// <summary>
        /// Calculates the sum of two double numbers
        /// </summary>
        /// <returns>X + Y</returns>
        public double Operate()
        {
            double result = X + Y;

            if (double.IsInfinity(result))
            {
                Revise.ArgumentException(Resource.OutOfRange, nameof(result));
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Calculates the Log10 of two double numbers
        /// </summary>
        /// <returns>Log10(X)</returns>
        public double Operate()
        {
            double result = Math.Log10(X);

            if (double.IsNaN(result))
            {
                Revise.ArgumentException(Resource.ValueOfXLessThanZero, nameof(X));
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Checking X, Y values.
        /// </summary>
        private void СheckXY()
        {
            StringBuilder error = new StringBuilder();

            if (double.IsNaN(X))
            {
                AddError(Resource.UnableX);
            }

            if (double.IsNaN(Y))
            {
                AddError(Resource.UnableY);
            }

            if (double.IsInfinity(X))
            {
                AddError(Resource.OutOfRangeX);
            }

            if (double.IsInfinity(Y))
            {
                AddError(Resource.OutOfRangeY);
            }

            if (error.Length > 0)
            {
                Revise.ArgumentException(GetResultErrors());
            }

            #region Helpers
            void AddError(string message)
            {
                if (error.Length > 0)
                {
                    error.Append(GetNewLine());
                }
                error.AppendFormat(message);
            }

            string GetNewLine()
            {
                return(Environment.NewLine);
            }

            string GetResultErrors()
            {
                return(string.Format("{0}{1}{2}", Resource.UnableCompleteOperation, GetNewLine(), error.ToString()));
            }

            #endregion
        }