コード例 #1
0
        public void IterativeMinTest()
        {
            BigInteger answer = 0;

            fibClassOnTest = new ComputeFibNumIteratively();
            answer         = fibClassOnTest.ComputeFib(0);
            Assert.AreEqual((UInt64)0, answer);
        }
コード例 #2
0
        public void ComputeRecursiveTest()
        {
            BigInteger answer = 0;

            fibClassOnTest = new ComputeFibNumRecursively();
            answer         = fibClassOnTest.ComputeFib(25);
            Assert.AreEqual((UInt64)75025, answer);
        }
コード例 #3
0
        public void IterativeMaxTest()
        {
            BigInteger answer = 0;

            fibClassOnTest = new ComputeFibNumIteratively();
            answer         = fibClassOnTest.ComputeFib(1476);
            //Actual 1.3069892237633987E+308
            //Displayed 1.3069892237634E+308
            Assert.AreEqual(1.3069892237633987E+308, answer);
        }
コード例 #4
0
        /// <summary>Simple method using very rudimentary Dependency injection through use of IComputeFib interface insctance being passed in and used.
        /// Also measures the execution time in miliseconds. Useful for algorithm tweaking.
        /// </summary>
        /// <param name="comp">IComputeFib instance to compute seq with</param>
        /// <param name="seqNum">Number in Sequence to find</param>
        /// <returns>A BigInteger containing requested position in Fibonacci sequence </returns>
        private BigInteger InternalTimedComputation()

        //public BigInteger TimedComputation()
        {
            BigInteger fibNum = 0;
            //For monitoring execution times
            Stopwatch sw = Stopwatch.StartNew();

            //Use ICompFib class to compute number
            try
            {
                fibNum = timedCompute.ComputeFib(sequenceNum);
            }
            catch (Exception computeException)
            {
                //We could dive into computeException.Message and log it etc...but I'm not going to to that for brevity's sake
                throw new ApplicationException("A general error occurred while trying to compute Fibonacci sequence", computeException);
            }

            sw.Stop();
            timeSpan = sw.Elapsed.TotalMilliseconds;

            return(fibNum);
        }