示例#1
0
        /// <summary>
        /// Fires all methods (Func delegates) from searchMethhods list and prints out their outputs, if any.
        /// Displays elapsed time for each method it runs.
        /// </summary>
        /// <typeparam name="TOutput">Return type of methods (Func delegates) in provided List</typeparam>
        /// <param name="expectedOutput">What should the method return? How is it called? Example: "first non repeating character"</param>
        /// <param name="searchMethods">List of Func delegates with all the methods you want to test</param>
        public static void TestAllMethods(string stringToSearchIn, string expectedOutput, params Func <string, TOutput>[] searchMethods)
        {
            int methodCount = searchMethods.Length;

            for (int methodIndex = 0; methodIndex < methodCount; methodIndex++)
            {
                Func <string, TOutput> selectedMethod = searchMethods[methodIndex];

                Stopwatcher.Start();
                DisplaySearchResult(selectedMethod.Method.Name, expectedOutput, selectedMethod.Invoke(stringToSearchIn));
                Stopwatcher.Stop();
            }
        }
示例#2
0
        static void Main2(string[] args)
        {
            UtilityPlus.Class1.msg();

            System.Console.WriteLine("Hello World!");
            SomeAction("yes");

            string param1 = "test";
            bool   result = Stopwatcher.Track(() => SomeAction(param1), "test");

            Stopwatcher.Show();

            System.Console.WriteLine(Memory.Show());
        }
示例#3
0
 private void StartOrStopOrContinueStopwatcher()
 {
     if (IsStopwatcherExists)
     {
         if (IsStopwatcherCounting) // need to stop
         {
             Stopwatcher.Stop();
             IsStopwatcherCounting = false;
         }
         else // need to continue
         {
             Stopwatcher.Start();
             IsStopwatcherCounting = true;
         }
     }
     else // need to start new stopwatch
     {
         Stopwatcher           = Stopwatch.StartNew();
         IsStopwatcherExists   = true;
         IsStopwatcherCounting = true;
     }
 }
示例#4
0
        public static void RunAllMethods(int[] inputArray, int[] correctAnswer)
        {
            int methodsCount = allMethods.Count;

            for (int i = 0; i < methodsCount; i++)
            {
                int   arrayLength = inputArray.Length;
                int[] newArray    = new int[arrayLength];
                Array.Copy(inputArray, newArray, arrayLength);

                Stopwatcher.Start();
                int[] result = allMethods[i].Invoke(newArray);
                Stopwatcher.Stop();

                Console.WriteLine($"{allMethods[i].Method.ToString()} produced the following result:");
                int resultCount = result.Length;
                for (int r = 0; r < resultCount; r++)
                {
                    Console.Write(result[r].ToString() + " ");
                }
                string resultEvaluation = result.SequenceEqual(correctAnswer) ? "correct" : "incorrect";
                Console.WriteLine($"- this output is {resultEvaluation}.\n");
            }
        }