public void SortExample() { var sorter = new HeapSorter<int>(); var list = new List<int> {13, 5, 77, 9, 12}; sorter.Sort(list, Comparer<int>.Default); Assert.AreEqual(5, list[0]); Assert.AreEqual(9, list[1]); Assert.AreEqual(12, list[2]); Assert.AreEqual(13, list[3]); Assert.AreEqual(77, list[4]); }
public static void ArraySorted([Random(0, 1000, 100, Distinct = true)] int n) { // Arrange var sorter = new HeapSorter <int>(); var intComparer = new IntComparer(); var(correctArray, testArray) = RandomHelper.GetArrays(n); // Act sorter.Sort(testArray, intComparer); Array.Sort(correctArray); // Assert Assert.AreEqual(correctArray, testArray); }
public void Sort_DoesNotChange_OriginalInput() { //arrange const int firstElement = 5, lastElement = 3; var original = new List <int> { firstElement, 2, 4, 6, 1, lastElement }; var sorter = new HeapSorter <int>(); //act var sorted = sorter.Sort(original); //assert original[0].Should().Be(firstElement); original[5].Should().Be(lastElement); }
public void SortExample() { var sorter = new HeapSorter <int>(); var list = new List <int> { 13, 5, 77, 9, 12 }; sorter.Sort(list, Comparer <int> .Default); Assert.AreEqual(5, list[0]); Assert.AreEqual(9, list[1]); Assert.AreEqual(12, list[2]); Assert.AreEqual(13, list[3]); Assert.AreEqual(77, list[4]); }
public void Sort_Returns_AscOrderedCollection() { //arrange var original = new List <int> { 5, 2, 4, 6, 1, 3 }; var sorter = new HeapSorter <int>(); //act var sorted = sorter.Sort(original).ToList(); //assert var prev = sorted[0]; for (var i = 1; i < sorted.Count; i++) { prev.Should().BeLessOrEqualTo(sorted[i]); prev = sorted[i]; } }
/// <summary> /// 堆排序 /// </summary> /// <param name="i"></param> public void HeapSorter(int i = 0) { Action <bool> action = (p) => { IList <int> list2 = list; HeapSorter <int> .Sort(list, true); if (p) { Trace.WriteLine("堆排序:"); Trace.WriteLine(list2.ToJson()); } }; if (i < 1) { action(true); } else { string data = ActionExtensions.Time(() => action(false), "堆排序", i); Trace.WriteLine(data.Replace("<br />", Environment.NewLine)); } }
public void ExceptionNullComparer1() { var sorter = new HeapSorter<int>(); sorter.Sort(new List<int>(), (IComparer<int>)null); }
public void ExceptionNullList3() { var sorter = new HeapSorter<int>(); sorter.Sort(null, SortOrder.Ascending); }
public void ExceptionNullList2() { var sorter = new HeapSorter<int>(); sorter.Sort(null, Comparer<int>.Default); }
public void ExceptionNullList1() { var sorter = new HeapSorter<int>(); sorter.Sort(null); }
public void TestHeapSortNullComparer1() { HeapSorter <int> sorter = new HeapSorter <int>(); sorter.Sort(new List <int>(), (IComparer <int>)null); }
public void TestHeapSortNullList3() { HeapSorter <int> sorter = new HeapSorter <int>(); sorter.Sort(null, SortOrder.Ascending); }
public void TestHeapSortNullList2() { HeapSorter <int> sorter = new HeapSorter <int>(); sorter.Sort(null, Comparer <int> .Default); }
public void TestHeapSortNullList1() { HeapSorter <int> sorter = new HeapSorter <int>(); sorter.Sort(null); }