Пример #1
0
        public void Add_Integers_ReturnsSum(int start, int amount, int expectedResult)
        {
            ISimpleCalculator calc = generateCalculator();
            int result             = calc.Add(start, amount);

            Assert.AreEqual(expectedResult, result);
        }
 public IActionResult Add([FromBody] SimpleCalculatorData input)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     return(Ok(_calculator.Add(input.value1, input.value2)));
 }
Пример #3
0
 // GET: api/Calculator/Add/5/6
 public IHttpActionResult Add(int input1, int input2)
 {
     try
     {
         result = _iCalculator.Add(input1, input2);
         return(Ok(result));
     }
     catch (Exception)
     {
         return(InternalServerError(new Exception("Addition failed")));
     }
 }
Пример #4
0
        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,
            });
Пример #5
0
        static void Main(string[] args)
        {
            #region CSharpCalculatorComponent
            ICSharpCalculatorComponentCalculator cSharpCalculatorComponentCalculator = (ICSharpCalculatorComponentCalculator) new CSharpCalculatorComponentCalculator();
            int result = cSharpCalculatorComponentCalculator.Sub(9, 8);
            #endregion

            //Using COM interop
            ISimpleCalculator a = (ISimpleCalculator) new Calculator();
            var interopresult   = a.Add(4, 66);

            ATLSimpleCalculatorComponentLib.ISimpleCalculator calc = new ATLSimpleCalculatorComponentLib.Calculator();
            result = calc.Add(4, 6);

            Console.WriteLine(result);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        public async Task <int> Add(int start, int amount)
        {
            var response = await Task <int> .Run(() => _simpleCalculator.Add(start, amount));

            return(response);
        }
        public void Add_Normal_ReturnsExpectedResult(int start, int amount, int expectedResult)
        {
            var result = Calculator.Add(start, amount);

            Assert.That(result, Is.EqualTo(expectedResult));
        }