public void Sort_PassOneElementArray_ReturnOneElementArray() { var heapSorting = new HeapSorting(); var sortedArray = heapSorting.Sort(_oneElementArray, 0, _oneElementArray.Length - 1); CollectionAssert.AreEqual(sortedArray, _oneElementArray); }
public void Sort_PassValidArray_ReturnSortedArray() { var heapSorting = new HeapSorting(); var sortedArray = heapSorting.Sort(_toSortArray, 0, _toSortArray.Length - 1); CollectionAssert.AreEqual(sortedArray, _referenceSortedArray); }
public void Sort_PassEmptyArray_ReturnEmptyArray() { var heapSorting = new HeapSorting(); var sortedArray = heapSorting.Sort(_emptyArray, 0, _emptyArray.Length - 1); CollectionAssert.AreEqual(sortedArray, _emptyArray); }
public void Test_Heap_Sort_When_Input_IsCorrect() { int[] array = new int[] { 10, 20, 5, 6, 9, 7 }; HeapSorting.Sort(array); //CommonMethod.RunTestsForSortAlgorithm(HeapSorting.Sort); }
public void HeapSorting_Sort__SuccessResult() { ISorting testClass = new HeapSorting(); int[] array = new int[] { 1, 0, 2, 9, 3, 8, 4, 7, 5, 6 }; testClass.Sort(array); array.Should().Equal(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); }
public void Sort_DifferentValues_CorrectResult() { var needSortVales = new[] { 3, 1, 9, 6.5, -8, 3.8 }; var expectedVales = new[] { -8, 1, 3, 3.8, 6.5, 9 }; var result = HeapSorting.HeapSort(needSortVales); CollectionAssert.AreEqual(expectedVales, result); }
public void FindStartingIndexTest() { // Arrange var numbers = new int[6]{1,2,3,4,5,6}; // Act var startingIndex = new HeapSorting(numbers).FindStartingIndex(); // Assert Assert.Equal(2, startingIndex); }
/// <summary> /// Пример использования /// Сначала выводим на экран неотсортированный массив, после чего сортируем и выводим сортированый /// </summary> private static void Main() { Console.WriteLine("Before sorting: "); var beforeSorting = new[] { 7, 5, 2, 0, -5, 2, 3 }; Print(beforeSorting); Console.WriteLine(); Console.WriteLine("After sorting: "); var afterSorting = HeapSorting.HeapSort(beforeSorting); Print(afterSorting); Console.ReadKey(); }
public void HeapSorting_Test() { var rand = new Random(); var list = Enumerable .Range(1, 10000) .Select(x => rand.Next()) .ToList(); var actual = HeapSorting.Sort(list); list.Sort(); Assert.Equal(list, actual); }
public void MaxHeapify_Should_Heap() { IList <int> list = new List <int> { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 }; list = list.BuildHeap(); for (int i = 0; i < list.Count - 1; ++i) { var leftIndex = HeapSorting.Left(i); var rightIndex = HeapSorting.Right(i); if (leftIndex < list.Count) { Assert.That(list[i] >= list[leftIndex], $"{list[i]} > {list[leftIndex]}"); } if (rightIndex < list.Count) { Assert.That(list[i] >= list[rightIndex], $"{list[i]} > {list[rightIndex]}"); } } }
public QueuePriority(IList <T> collection) { SortingStrategy = new HeapSorting(); SortingStrategy.BuildMaxHeap(collection); Collection = new List <T>(collection); }
public QueuePriority() { SortingStrategy = new HeapSorting(); Collection = new List <T>(); }
public void HeapSorting_Sort() { ISorting testClass = new HeapSorting(); testClass.Sort(SortedData); }