/// <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 static void Main() { ArithmeticCalculator.Add(1.9, 1, 7); ArithmeticCalculator.Add(second: 1, first: 1.8, third: 7); var lastName = "Bob"; var firstName = "Tabor"; firstName = lastName; Console.WriteLine("{0} {1}", firstName, lastName); firstName = "Tabor"; Console.WriteLine("{0} {1}", firstName, lastName); var variable = 4.0999; // implicit typing. literal assignment var v2 = 90; Console.WriteLine("{0} {1}", variable, v2); v2 = 1000; Console.WriteLine("{0} {1}", variable, v2); }
public void PassingAdditionTest() { Assert.Equal(9, _arithmeticCalculator.Add(5, 4)); }
public void PassingAdditionTest() { Assert.IsTrue(_arithmeticCalculator.Add(5, 4) == 9); }