예제 #1
0
        public void Setter_IndexMinValue_ThrowException()
        {
            int index = 0;
            var sf    = new Quiz5SuperMix.SuperFibs();

            Console.WriteLine("{0}:{1}, steps {2}", index, sf[index], sf.StepsCount);
        }
예제 #2
0
        public void SuperFibs_LargeIndex_ReturnValueCorrect()
        {
            int index = 20;
            var sf    = new Quiz5SuperMix.SuperFibs();

            Assert.AreEqual(35890, sf[index]);
        }
예제 #3
0
        public void SuperFibs_InitialIndex_ReturnValueCorrect()
        {
            int index = 3;
            var sf    = new Quiz5SuperMix.SuperFibs();

            Assert.AreEqual(1, sf[index]);
        }
예제 #4
0
        static void Main(string[] args)
        {
            SuperFibs sf = new SuperFibs();

            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine(i + " : " + sf[i]);
            }
            try
            {
                Console.WriteLine(sf[0]);
            }
            catch (IndexOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }



            Console.WriteLine("1: {0}, steps {1}", sf[1], sf.StepsCount); // prints 1: 0, steps 0
            Console.WriteLine("2: {0}, steps {1}", sf[2], sf.StepsCount); // prints 2: 1, steps 0
            Console.WriteLine("3: {0}, steps {1}", sf[3], sf.StepsCount); // prints 3: 1, steps 0
            Console.WriteLine("5: {0}, steps {1}", sf[5], sf.StepsCount); // prints 5: 4, steps 2
            Console.WriteLine("9: {0}, steps {1}", sf[9], sf.StepsCount); // prints 9: 44, steps 4
            Console.WriteLine("7: {0}, steps {1}", sf[7], sf.StepsCount); // prints 7: 13, steps 0 (because it's already in the cache)
            Console.WriteLine("9: {0}, steps {1}", sf[9], sf.StepsCount);

            //Prompt user to enter seconds
            float userTime;

            while (true)
            {
                Console.Write("Please enter number of seconds: ");

                try
                {
                    userTime = float.Parse(Console.ReadLine());
                    break;
                }
                catch (FormatException)
                {
                    Console.WriteLine("Enter numbers only");
                }
            }

            var startTime = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; //starting time point


            for (int i = 1; i < MaxValue; i++)
            {
                Console.WriteLine(i + " : " + sf[i]);
                if (((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - startTime) > userTime)
                {
                    Console.WriteLine(i + " numbers are generated in " + ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - startTime) + " second(s)");
                    break;
                }
            }
            Console.ReadKey();
        }
예제 #5
0
        public void SuperFibs_StepsCountByCompute_ReturnValueCorrect()
        {
            int index = 9;
            var sf    = new Quiz5SuperMix.SuperFibs();

            Console.WriteLine("{0}:{1}, steps {2}", index, sf[index], sf.StepsCount);

            Assert.AreEqual(6, sf.StepsCount);
        }
예제 #6
0
        public void SuperFibs_StepsCountFromCache_ReturnValueCorrect()
        {
            int index = 6;
            var sf    = new Quiz5SuperMix.SuperFibs();

            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine("{0}:{1}, steps {2}", i, sf[i], sf.StepsCount);
            }
            Console.WriteLine("{0}:{1}, steps {2}", index, sf[index], sf.StepsCount);

            Assert.AreEqual(0, sf.StepsCount);
        }
예제 #7
0
        static void Main(string[] args)
        {
            SuperFibs sf = new SuperFibs();

            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine("{0}:{1}, steps {2}", i, sf[i], sf.StepsCount);
            }
            Console.WriteLine("{0}:{1}, steps {2}", 5, sf[5], sf.StepsCount);

            Console.WriteLine("{0}:{1}, steps {2}", 4, sf[4], sf.StepsCount);

            Console.WriteLine("{0}:{1}, steps {2}", 12, sf[12], sf.StepsCount);

            Console.WriteLine("Please enter the number of seconds(floating point number) to compute the 'Super Finbonacci': ");
            double seconds;
            var    watch = new System.Diagnostics.Stopwatch();

            try
            {
                double.TryParse(Console.ReadLine(), out seconds);
                int index = 1;

                watch.Start();

                while (watch.Elapsed.TotalSeconds < seconds)
                {
                    Console.WriteLine("{0}:{1}", index, sf[index]);
                    index++;
                }
                watch.Stop();
                Console.WriteLine("{0} super-fib numbers generated in under {1} seconds", index, seconds);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Please input correct number" + ex.Message);
            }

            Console.WriteLine("Press any key");
            Console.ReadKey();
        }