public void TestQuickSort()
        {
            QuickSortClass qs = new QuickSortClass();

            int[] test = new int[] { 11, 2, 3, 56, 34, 89, 4, 78, 90, 12, 13, 16, 56 };
            qs.QuickSort(test, 0, test.Length - 1);
            var result = test;
        }
Example #2
0
        public void CanSortArray(int[] input, int[] expected)
        {
            //Act
            QuickSortClass.QuickSort(input);

            //Assert
            Assert.Equal(expected, input);
        }
Example #3
0
        public void Test3Elements()
        {
            var a = 1;
            var b = 3;
            var c = 2;

            QuickSortClass.QuickSort(a, b, c);
            Assert.IsTrue(a < c && c < b);
        }
Example #4
0
        public void CanSortAnEmptyArray()
        {
            //Arrange
            int[] testArray = new int[0];
            int[] expected  = new int[0];

            //Act
            QuickSortClass.QuickSort(testArray);

            //Assert
            Assert.Equal(expected, testArray);
        }
Example #5
0
        public void CanSortAnArrayWithNegativeIntegers()
        {
            //Arrange
            int[] testArray = new int[] { 5, -12, 0, -22, 17, 9, -7 };
            int[] expected  = new int[] { -22, -12, -7, 0, 5, 9, 17 };

            //Act
            QuickSortClass.QuickSort(testArray);

            //Assert
            Assert.Equal(expected, testArray);
        }
Example #6
0
        public void CanSortAnArrayOfLengthOne()
        {
            //Arrange
            int[] testArray = new int[] { 5 };
            int[] expected  = new int[] { 5 };

            //Act
            QuickSortClass.QuickSort(testArray);

            //Assert
            Assert.Equal(expected, testArray);
        }
Example #7
0
        public void Test100IdenticalElements()
        {
            var array = new int[100];

            QuickSortClass.QuickSort(array);

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = 0;
                Assert.AreEqual(array[i], 0);
            }
        }
Example #8
0
        public void Test1000Elements()
        {
            var random = new Random();
            var array  = new int[1000];

            QuickSortClass.QuickSort(array);

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = random.Next(100);
                var x = random.Next(100);
                var y = random.Next(100);
                while (x < y)
                {
                    x = random.Next(100);
                    y = random.Next(100);
                }
                Assert.IsTrue(array[x] > array[y]);
            }
        }
Example #9
0
 /// <summary>
 /// 在构造函数中直接进行初始化
 /// binarySearch和quickSort
 /// </summary>
 public Adapter()
 {
     this.binarySearch = new BinarySearchClass();
     this.quickSort = new QuickSortClass();
 }
Example #10
0
 /// <summary>
 /// 实例化
 /// </summary>
 public Adapter()
 {
     sortObj   = new ScoreLibs.QuickSortClass();
     searchObj = new BinarySearchClass();
 }
        private BinarySearchClass searchObj; //定义适配者BinarySearchClass对象

        public OperationAdapter()
        {
            sortObj   = new QuickSortClass();
            searchObj = new BinarySearchClass();
        }
Example #12
0
        static void Main(string[] args)
        {
            ArrayClass array = new ArrayClass(100000);

            array.SetRandomArray(0, 100);
            //array.ShowArray();

            #region Сортировка пузырьком

            BubbleSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine(
                $"Сортировка пузырьком: {BubbleSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Шейкерная сортировка

            ShakerSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Шейкерная сортировка: {ShakerSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Сортировка вставками

            InsertionSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Сортировка вставками: {InsertionSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Быстрая сортировка

            Stopwatch timer = new Stopwatch();
            timer.Start();
            QuickSortClass.DoSort(ref array, 0, array.Size - 1);
            timer.Stop();
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Быстрая сортировка: {timer.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Пирамидальная сортировка

            HeapSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Пирамидальная сортировка: {HeapSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            Console.ReadLine();
        }
Example #13
0
        public void TestEmptyArray()
        {
            var array = new int[] { };

            QuickSortClass.QuickSort(array);
        }