Esempio n. 1
0
        public void FibonacciOfTwentyTestMethod()
        {
            var actual   = FibonacciManager.Calculate(20);
            var expected = 6765;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void FibonacciOfOneTestMethod()
        {
            var actual   = FibonacciManager.Calculate(1);
            var expected = 1;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
 public void FibonacciNegativeNumbersTestMethod()
 {
     long[] values   = { -8, -7, -6, -5, -4, -3, -2, -1 };
     long[] expected = { -21, 13, -8, 5, -3, 2, -1, 1 };
     for (byte index = 0; index < values.Length; index++)
     {
         Assert.AreEqual(FibonacciManager.Calculate(values[index]), expected[index]);
     }
 }
Esempio n. 4
0
 public FibonacciNumberResponse FibonacciNumber(FibonacciNumberRequest request)
 {
     if (request == null)
     {
         throw new FaultException <ArgumentNullException>(new ArgumentNullException("request"), "null arguments are invalid");
     }
     try
     {
         var result = new FibonacciNumberResponse(FibonacciManager.Calculate(request.n));
         return(result);
     }
     catch (ArgumentOutOfRangeException exp)
     {
         throw new FaultException <ArgumentOutOfRangeException>(exp, exp.Message);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Esempio n. 5
0
        public async Task <FibonacciNumberResponse> FibonacciNumberAsync(FibonacciNumberRequest request)
        {
            if (request == null)
            {
                throw new FaultException <ArgumentNullException>(new ArgumentNullException("request"), "null arguments are invalid");
            }

            return(await Task.Run <FibonacciNumberResponse>(() =>
            {
                try
                {
                    var result = new FibonacciNumberResponse(FibonacciManager.Calculate(request.n));
                    return result;
                }
                catch (ArgumentOutOfRangeException exp)
                {
                    throw new FaultException <ArgumentOutOfRangeException>(exp, exp.Message);
                }
                catch (Exception ex)
                {
                    throw new FaultException(ex.Message);
                }
            }));
        }