public void HeapSortWithRandomIntegerArray() { var sortedIndices = new []{ 5, 2, 8, 6, 0, 4, 1, 7, 3, 9 }; 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); } } } } } }