public void MergeSort_WithSortedDuplicateValues()
        {
            var values = new List <int>(Constants.ArrayWithSortedDuplicateValues);

            MergeSort.Sort(values, 0, values.Count - 1);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }
示例#2
0
        public void QuickSort_WithReverselySortedDistinctValues()
        {
            var values = new List <int>(Constants.ArrayWithReverselySortedDistinctValues);

            QuickSort.Sort(values, 0, values.Count - 1);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }
        public void Merge()
        {
            var values1 = new List <int> {
                10, 1
            };

            MergeSort.Merge(values1, 0, 0, 1);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values1));

            var values2 = new List <int> {
                10, 1
            };

            // Indexes are such that the list will not get sorted,
            MergeSort.Merge(values2, 0, 1, 1);
            Assert.IsTrue(values2[0] == 10);
            Assert.IsTrue(values2[1] == 1);

            var values3 = new List <int> {
                10, 41, 3, 10
            };

            MergeSort.Merge(values3, 0, 1, 3);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values3));
        }
示例#4
0
        /// <summary>
        /// Tests the correctness of <paramref name="sortMethod"/>.
        /// </summary>
        /// <param name="sortMethod">The sort method that is being tested. </param>
        public static void TestSortMethodWithDifferentInputs(Action <List <int> > sortMethod)
        {
            var values = new List <int>(Constants.ArrayWithDistinctValues);

            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));

            values = new List <int>(Constants.ArrayWithDuplicateValues);
            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));

            values = new List <int>(Constants.ArrayWithSortedDistinctValues);
            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));

            values = new List <int>(Constants.ArrayWithSortedDuplicateValues);
            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));

            values = new List <int>(Constants.ArrayWithReverselySortedDistinctValues);
            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));

            values = new List <int>(Constants.ArrayWithReverselySortedDuplicateValues);
            sortMethod(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }
        public void Sort_Recursive_WithDuplicateValues()
        {
            var values = new List <int>(Constants.ArrayWithDuplicateValues);

            InsertionSort.Sort_Recursive(values, values.Count - 1);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }
        public void Sort_WithReverselySortedDistinctValues()
        {
            var values = new List <int>(Constants.ArrayWithReverselySortedDistinctValues);

            values = HeapSort.Sort(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }
        public void Sort_WithDistinctValues()
        {
            // SortTests.TestSortMethodWithDifferentInputs(HeapSort.Sort);
            var values = new List <int>(Constants.ArrayWithDistinctValues);

            values = HeapSort.Sort(values);
            Assert.IsTrue(UtilsTests.IsSortedAscendingly(values));
        }