public void TestMethod1() { AdditionOperator testAdditionOperator = new AdditionOperator(); testAdditionOperator.AddInput(); int expected = 8; int actual = result.AddInput(); Assert.AreEqual(expected, actual); }
private static void perform_op(double x, char op, CalculatorLogic cl) { IBinaryOperator subOperator = new SubtractionOperator(); IBinaryOperator mulOperator = new MultiplicationOperator(); IBinaryOperator divOperator = new DivisionOperator(); IBinaryOperator addOperator = new AdditionOperator(); if (op == '+') cl.AcceptNumber (x, addOperator); else if (op == '-') cl.AcceptNumber (x, subOperator); else if (op == '*') cl.AcceptNumber (x,mulOperator); else if (op == '/') cl.AcceptNumber (x, divOperator); }
public void RunCalculator() { Console.WriteLine("Enter first number"); firstNumber = decimal.Parse(Console.ReadLine()); Console.WriteLine("\nEnter operator choice (+,-,*,/)"); mathOperator = Console.ReadLine(); //mathOperator = Console.ReadLine(); //Console.WriteLine("\nEnter second number"); //secondNumber = decimal.Parse(Console.ReadLine()); if (mathOperator == "+") { Console.WriteLine("\nEnter second number"); secondNumber = decimal.Parse(Console.ReadLine()); AdditionOperator add = new AdditionOperator(); add.Add(firstNumber, secondNumber); add.PrintResult(); } else if (mathOperator == "-") { Console.WriteLine("\nEnter second number"); secondNumber = decimal.Parse(Console.ReadLine()); SubtractionOperator subtract = new SubtractionOperator(); subtract.Subtract(firstNumber, secondNumber); subtract.PrintResult(); } else if (mathOperator == "*") { Console.WriteLine("\nEnter second number"); secondNumber = decimal.Parse(Console.ReadLine()); MultiplicationOperator multiply = new MultiplicationOperator(); multiply.Multiply(firstNumber, secondNumber); multiply.PrintResult(); } else if (mathOperator == "/") { Console.WriteLine("\nEnter second number"); secondNumber = decimal.Parse(Console.ReadLine()); DivisionOperator divide = new DivisionOperator(); divide.Division(firstNumber, secondNumber); //divide.PrintResult(); } else { Console.WriteLine("\nInvalid input entered."); CalculatorDisplay calculatorDisplay = new CalculatorDisplay(); calculatorDisplay.RunCalculator(); } //Console.WriteLine("\nEnter second number"); //secondNumber = decimal.Parse(Console.ReadLine()); Console.WriteLine("\nPerform new operation? (yes/no):"); string performNewOperationResponse = Console.ReadLine(); if (performNewOperationResponse == "yes") { CalculatorDisplay calculatorDisplay = new CalculatorDisplay(); calculatorDisplay.RunCalculator(); } else { Environment.Exit(0); } }