Beispiel #1
0
        /// <summary>
        /// 排序
        /// </summary>
        public int[] Sort(int[] Number)
        {
            //调用排序方法,返回值为int[]
            int[] number = sortObj.QuickSort(Number);

            return(number);
        }
Beispiel #2
0
        public void CanSortArray(int[] input, int[] expected)
        {
            //Act
            QuickSortClass.QuickSort(input);

            //Assert
            Assert.Equal(expected, input);
        }
        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;
        }
Beispiel #4
0
        public void Test3Elements()
        {
            var a = 1;
            var b = 3;
            var c = 2;

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

            //Act
            QuickSortClass.QuickSort(testArray);

            //Assert
            Assert.Equal(expected, testArray);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void CanSortAnArrayOfLengthOne()
        {
            //Arrange
            int[] testArray = new int[] { 5 };
            int[] expected  = new int[] { 5 };

            //Act
            QuickSortClass.QuickSort(testArray);

            //Assert
            Assert.Equal(expected, testArray);
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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]);
            }
        }
Beispiel #10
0
 public int[] Sort(int[] allGrade)
 {
     //该方法将传入的数组进行排序
     return quickSort.QuickSort(allGrade);
 }
 public int[] Sort(int[] array)
 {
     return(sortObj.QuickSort(array)); //调用适配者类QuickSortClass的排序方法
 }
Beispiel #12
0
        public void TestEmptyArray()
        {
            var array = new int[] { };

            QuickSortClass.QuickSort(array);
        }