コード例 #1
0
        public void FibonacciOfTwentyTestMethod()
        {
            var actual   = FibonacciManager.Calculate(20);
            var expected = 6765;

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void FibonacciOfOneTestMethod()
        {
            var actual   = FibonacciManager.Calculate(1);
            var expected = 1;

            Assert.AreEqual(expected, actual);
        }
コード例 #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]);
     }
 }
コード例 #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);
     }
 }
コード例 #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);
                }
            }));
        }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 public FibonacciService()
 {
     _fibonacciManager = new FibonacciManager();
 }