public void HeapSortWithDecreasingIntegerArray() { var sortedIndices = new[] {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); } }
public void HeapSortWithSpecialConstructedIntegerArray() { var sortedIndices = new[] {0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) { Assert.AreEqual(1, sortedIndices[i], "#01-" + i); break; } } sortedIndices = new[] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) { Assert.AreEqual(1, sortedIndices[i], "#02-" + i); break; } } sortedIndices = new[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) { Assert.AreEqual(1, sortedIndices[i], "#03-" + i); break; } } sortedIndices = new[] {1, 1, 1, 0, 1, 1, 1, 1, 1, 1}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) { Assert.AreEqual(0, sortedIndices[i], "#04-" + i); break; } } }
public void HeapSortWithDuplicateEntries() { var sortedIndices = new[] {1, 1, 1, 1, 2, 2, 2, 2, 3, 4}; ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) { Assert.AreEqual(4, sortedIndices[i], "#01-" + i); } else { if (i == 1) { Assert.AreEqual(3, sortedIndices[i], "#01-" + i); } else { if (i < 6) { if (sortedIndices[i] != 2) { Assert.Fail("#01-" + i); } } else { if (sortedIndices[i] != 1) { Assert.Fail("#01-" + i); } } } } } }