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 CanTryParseSingleDenseVector() { var data = new[] { 1.2f, 3.4f, 5.6e-78f }; var text = String.Format( "{1}{0}{2}{0}{3}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, data[0], data[1], data[2]); DenseVector vector; var ret = DenseVector.TryParse(text, out vector); Assert.IsTrue(ret); AssertHelpers.AlmostEqualList(data, (float[])vector, 1e-15); ret = DenseVector.TryParse(text, CultureInfo.CurrentCulture, out vector); Assert.IsTrue(ret); AssertHelpers.AlmostEqualList(data, (float[])vector, 1e-15); }
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); } } } } } }