/// <summary> /// Performs arithmetic calculation depending on operator. /// </summary> /// <returns>Calculation result</returns> /// <exception cref="System.NotSupportedException">Thrown in case of operator is not recognized</exception> private double MakeArithmeticCalculation() { if (Operator == OperatorType.Addition) { return(ArithmeticCalculator.Add((double)FirstOperand, (double)SecondOperand)); } else if (Operator == OperatorType.Subtraction) { return(ArithmeticCalculator.Subtract((double)FirstOperand, (double)SecondOperand)); } else if (Operator == OperatorType.Multiplication) { return(ArithmeticCalculator.Multiply((double)FirstOperand, (double)SecondOperand)); } else if (Operator == OperatorType.Division) { try { return(ArithmeticCalculator.Divide((double)FirstOperand, (double)SecondOperand)); } catch (System.DivideByZeroException) { State = ExecutorState.Error; return(0); } } else if (Operator == OperatorType.Inversion) { try { return(ArithmeticCalculator.Invert((double)FirstOperand)); } catch (System.DivideByZeroException) { State = ExecutorState.Error; return(0); } } else if (Operator == OperatorType.SquareRoot) { try { return(ArithmeticCalculator.SquareRoot((double)FirstOperand)); } catch (SquareRootOfNegativeException) { State = ExecutorState.Error; return(0); } } throw new System.NotSupportedException("unknown operation type"); }
public void FailingDivisionTest() { Assert.Equal(1, _arithmeticCalculator.Divide(8, 4)); }
public void FailingDivisionTest() { Assert.IsTrue(_arithmeticCalculator.Divide(8, 4) == 1); }