public void TestAddition() { Calculator.models.Calculator calc = new Calculator.models.Calculator(); decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.ADDITION); Assert.Equal(10.0m, result); }
public void TestDivision() { Calculator.models.Calculator calc = new Calculator.models.Calculator(); decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.DIVISTION); Assert.Equal(3.0m, result); }
public void TestMultiplikation() { Calculator.models.Calculator calc = new Calculator.models.Calculator(); decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.MULTIPLICATION); Assert.Equal(18.75m, result); }
public void TestSubtraktion() { Calculator.models.Calculator calc = new Calculator.models.Calculator(); decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.SUBTRACTION); Assert.Equal(5.0m, result); }
static void Main(string[] args) { var isRunning = true; models.Calculator calc = new models.Calculator(); Console.WriteLine("welcome to our calculator"); while (isRunning) { Console.WriteLine("Start your calculation."); Console.WriteLine("number 1:"); string number1Input = Console.ReadLine(); Console.WriteLine("number 2:"); string number2Input = Console.ReadLine(); Console.WriteLine("operation:"); string operation = Console.ReadLine(); decimal.TryParse(number1Input, out var number1); decimal.TryParse(number2Input, out var number2); CalculationType?calculationType = null; switch (operation) { case "+": calculationType = CalculationType.ADDITION; break; case "-": calculationType = CalculationType.SUBTRACTION; break; case "*": calculationType = CalculationType.MULTIPLICATION; break; case "/": calculationType = CalculationType.DIVISTION; break; } if (calculationType.HasValue) { Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value)); } Console.WriteLine("Do you want to continue? y/n"); string choice = Console.ReadLine(); if (choice.ToLower().Equals("n")) { isRunning = false; } } }
static void Main(string[] args) { Console.WriteLine(Enum.GetName(typeof(CalculationType), CalculationType.ADDITION)); models.Calculator calc = new models.Calculator(); Console.WriteLine("Welcome to our calculator"); Console.WriteLine("Number 1:"); string number1Input = Console.ReadLine(); Console.WriteLine("Number 2:"); string number2Input = Console.ReadLine(); Console.WriteLine("Operation (-,+,*,/):"); string operation = Console.ReadLine(); decimal.TryParse(number1Input, out var number1); decimal.TryParse(number2Input, out var number2); CalculationType?calculationType = null; switch (operation) { case "+": calculationType = CalculationType.ADDITION; break; case "-": calculationType = CalculationType.SUBTRACTION; break; case "*": calculationType = CalculationType.MULTIPLICATION; break; case "/": calculationType = CalculationType.DIVISTION; break; } if (calculationType.HasValue) { Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value)); } }