public void SubstractionInputArgumentReturnedValue(int leftValue, int rightValue, int expectedValue) { var leftNumber = new Number() { Value = leftValue }; var rightNumber = new Number() { Value = rightValue }; var result = BinaryOperations.Subsctraction(leftNumber, rightNumber); Assert.AreEqual(expectedValue, result.Value); }
/// <summary> /// The calculation of the converted expression. /// </summary> /// <param name="inputExpression"> Input the converted expression. </param> /// <param name="firstNumber"> The first number. </param> /// <param name="secondNumber"> The second number. </param> /// <returns> Result of calculating the expression. </returns> public static Number Counting(string inputExpression, Number firstNumber, Number secondNumber) { if (string.IsNullOrWhiteSpace(inputExpression)) { throw new ArgumentNullException("The input expression cannot be empty.", nameof(inputExpression)); } double result = 0; var temp = new Stack <double>(); for (int i = 0; i < inputExpression.Length; i++) { if (char.IsDigit(inputExpression[i])) { string a = string.Empty; while (!IsDelimeter(inputExpression[i]) && !IsOperator(inputExpression[i])) { a += inputExpression[i]; i++; if (i == inputExpression.Length) { break; } } temp.Push(double.Parse(a, CultureInfo.InvariantCulture)); i--; } else if (IsOperator(inputExpression[i])) { if (inputExpression[i] == '!') { firstNumber = new Number { Value = temp.Pop() } } ; else { firstNumber = new Number { Value = temp.Pop() }; secondNumber = new Number { Value = temp.Pop() }; } switch (inputExpression[i]) { case '+': result = BinaryOperations.Addition(secondNumber, firstNumber).Value; break; case '-': result = BinaryOperations.Subsctraction(secondNumber, firstNumber).Value; break; case '*': result = BinaryOperations.Multiplication(secondNumber, firstNumber).Value; break; case '/': result = BinaryOperations.Division(secondNumber, firstNumber).Value; break; case '%': result = BinaryOperations.DivisionReaminder(secondNumber, firstNumber).Value; break; case '^': result = UnaryOperations.Exponentiation(secondNumber, firstNumber).Value; break; case '!': result = UnaryOperations.Factorial(firstNumber).Value; break; } temp.Push(result); } } return(new Number { Value = temp.Peek() }); }