Ejemplo n.º 1
0
        public static void Run()
        {
            const int k_Len = 10;
            int[] array = new int[k_Len];
            Random rand = new Random();
            for (int i = 0; i < k_Len; i++)
            {
                array[i] = rand.Next(10);
                Console.Write(array[i].ToString() + " ");
            }

            Console.WriteLine();

            SorterBase[] sorts = new SorterBase[] { new SorterUp(), new SorterDown() };

            sorts[0].Sort(array);
            for (int u = 0; u < k_Len; u++)
            {
                Console.Write(array[u].ToString() + " ");
            }
            Console.WriteLine();

            sorts[1].Sort(array);
            for (int u = 0; u < k_Len; u++)
            {
                Console.Write(array[u].ToString() + " ");
            }
            Console.WriteLine();
        }
Ejemplo n.º 2
0
 private void TestA_ThrowNullException(SorterBase sorter)
 {
     try
     {
         sorter.Sort(null);
         Assert.IsEmpty("Should throw ArgumentNullException");
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOf <ArgumentNullException>(ex);
     }
 }
Ejemplo n.º 3
0
        private static long TestIntegersArraySortingMethod(string sortingName, SorterBase <int> st, int[] arrayToSort)
        {
            var watch = Stopwatch.StartNew();

            Console.Write($"{sortingName}: running");

            ISortingService <SorterBase <int>, int> _sortingService = new SortingService <SorterBase <int>, int>(st);

            watch.Start();
            _sortingService.SortItems((int[])arrayToSort.Clone());
            watch.Stop();

            Console.SetCursorPosition(0, Console.CursorTop);
            Console.WriteLine($"{sortingName} completed in \t\t {watch.ElapsedMilliseconds} ms");
            return(watch.ElapsedMilliseconds);
        }
Ejemplo n.º 4
0
        private void TestA_Sort(SorterBase sorter, int[] input)
        {
            var expected = input.Clone() as int[];

            Array.Sort(expected);

            sorter.Sort(input);
            var inputString = JsonConvert.SerializeObject(input);

            Console.WriteLine($"input: {inputString}");

            var expectedString = JsonConvert.SerializeObject(expected);

            Console.WriteLine($"expected: {expectedString}");

            Assert.AreEqual(expectedString, inputString);
        }