public void DivideTest() { //Arrange var calculator = new ConsoleCalculatorCreator().CreateCalculator(); //Act var expected = 4; var result = calculator.Calculate(12, 3, Operation.Divide); //Assert Assert.Equal(expected, result); }
public void SubtractTest() { //Arrange var calculator = new ConsoleCalculatorCreator().CreateCalculator(); //Act var expected = 3; var result = calculator.Calculate(7, 4, Operation.Subtract); //Assert Assert.Equal(expected, result); }
public void MultiplyTest() { //Arrange var calculator = new ConsoleCalculatorCreator().CreateCalculator(); //Act var expected = 9; var result = calculator.Calculate(3, 3, Operation.Multiply); //Assert Assert.Equal(expected, result); }
public void AddTest() { //Arrange var calculator = new ConsoleCalculatorCreator().CreateCalculator(); //Act var expected = 6; var result = calculator.Calculate(2, 4, Operation.Add); //Assert Assert.Equal(expected, result); }
static void Main(string[] args) { double firstValue, secondValue; byte choose; while (true) { Console.WriteLine("enter the first value"); var firstValueInput = Console.ReadLine(); if (!double.TryParse(firstValueInput, out firstValue)) { break; } Console.WriteLine("enter the second value"); var secondValueInput = Console.ReadLine(); if (!double.TryParse(secondValueInput, out secondValue)) { break; } Console.WriteLine( "choose th operation:\n" + "0 - add\n" + "1 - subtract\n" + "2 - multiply\n" + "3 - divide\n" ); var chooseInput = Console.ReadLine(); if (!byte.TryParse(chooseInput, out choose)) { break; } var calculator = new ConsoleCalculatorCreator().CreateCalculator(); var op = (Operation)choose; try { calculator.Calculate(firstValue, secondValue, op); calculator.ShowResult(); } catch (Exception ex) { Console.WriteLine(ex); } } }