Exemple #1
0
 public void DoTest()
 {
     String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     Assert.IsTrue(SortHelper.IsSorted(a));
     Shuffle.Do(a);
     Assert.IsFalse(SortHelper.IsSorted(a));
 }
        public void SortTest_DESC()
        {
            String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            Shuffle.Do(a);

            Assert.IsFalse(SortHelper.IsSorted(a, SortOrder.DESC));
            MergeSort.Sort(a, SortOrder.DESC);
            Assert.IsTrue(SortHelper.IsSorted(a, SortOrder.DESC));
        }
        public void SortTest_DESC_DuplicateKey()
        {
            String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "3", "4", "5", "3", "4", "5", "3", "4", "5" };
            Shuffle.Do(a);

            Assert.IsFalse(SortHelper.IsSorted(a, SortOrder.DESC));
            Quick3WaySort.Sort(a, SortOrder.DESC);
            Assert.IsTrue(SortHelper.IsSorted(a, SortOrder.DESC));
        }
        public void SortWithComparerTest_DESC()
        {
            Point[] points = new Point[10];
            for (int i = 0; i < 10; i++)
            {
                points[i] = new Point(i, 10 - i);
            }
            Shuffle.Do(points);

            Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC));
            MergeSort.Sort(points, Point.X_ORDER, SortOrder.DESC);
            Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC));
        }
        public void SortWithComparerTest()
        {
            Point[] points = new Point[10];
            for (int i = 0; i < 10; i++)
            {
                points[i] = new Point(i, 10 - i);
            }
            Shuffle.Do(points);

            Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER));
            ShellSort.Sort(points, Point.X_ORDER);
            Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER));
        }
        public void SortWithComparerTest_DESC_DuplicateKey()
        {
            Point[] points = new Point[19];
            for (int i = 0; i < 10; i++)
            {
                points[i] = new Point(i, 10 - i);
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 3; j <= 5; j++)
                {
                    points[10 + i * 3 + j - 3] = new Point(j, 10 - i);
                }
            }
            Shuffle.Do(points);

            Assert.IsFalse(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC));
            Quick3WaySort.Sort(points, Point.X_ORDER, SortOrder.DESC);
            Assert.IsTrue(SortHelper.IsSorted(points, Point.X_ORDER, SortOrder.DESC));
        }
Exemple #7
0
        public void DoTest_Different()
        {
            String[] a1 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            String[] a2 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

            Shuffle.Do(a1);
            Shuffle.Do(a2);
            Assert.IsFalse(SortHelper.IsSorted(a1));
            Assert.IsFalse(SortHelper.IsSorted(a2));

            var same = true;

            for (int i = 0; i < 10; i++)
            {
                if (a1[i] != a2[i])
                {
                    same = false;
                    break;
                }
            }
            Assert.IsFalse(same);
        }