public void Divide_Integers_ReturnsDivision(int start, int by, int expectedResult) { ISimpleCalculator calc = generateCalculator(); int result = calc.Divide(start, by); Assert.AreEqual(expectedResult, result); }
public IHttpActionResult Divide(int input1, int input2) { try { result = _iCalculator.Divide(input1, input2); return(Ok(result)); } catch (DivideByZeroException) { return(InternalServerError(new Exception("DivideByZeroException"))); } }
public double GetCalculation(CalculationRequest request) { _logger.LogInformation("Processing a calculation request."); return(request.Type switch { CalculationType.Add => _calculator.Add(request.Start, request.Amount), CalculationType.Subtract => _calculator.Subtract(request.Start, request.Amount), CalculationType.Multiply => _calculator.Multiply(request.Start, request.By), CalculationType.Divide => _calculator.Divide(request.Start, request.By), CalculationType.Prime => _calculator.GetPrimeNumber(request.Index), _ => 0, });
public IActionResult Divide([FromBody] SimpleCalculatorData input) { try { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(_calculator.Divide(input.value1, input.value2))); } catch (System.DivideByZeroException) { return(BadRequest()); } }
private static int processOperation(string operation, Tuple <int, int> numbers, ISimpleCalculator calc) { switch (operation) { case "a": return(calc.Add(numbers.Item1, numbers.Item2)); case "s": return(calc.Subtract(numbers.Item1, numbers.Item2)); case "m": return(calc.Multiply(numbers.Item1, numbers.Item2)); case "d": return(calc.Divide(numbers.Item1, numbers.Item2)); default: return(0); } }
public async Task <int> Divide(int start, int by) { var response = await Task <int> .Run(() => _simpleCalculator.Divide(start, by)); return(response); }
public void Divide_DivideByZero_DivideByZeroException(int start, int by) { ISimpleCalculator calc = generateCalculator(); Assert.Throws <DivideByZeroException>(() => calc.Divide(5, 0)); }
public void Divide_Normal_ReturnExpectedResult(int start, int by, int expectedResult) { var result = Calculator.Divide(start, by); Assert.That(result, Is.EqualTo(expectedResult)); }