public void Shuffle_Empty_Test() { int[] actual = new int[0]; int[] expected = new int[0]; SortingUtils.Shuffle(actual); CollectionAssert.AreEquivalent(expected, actual); }
public void ShuffleTest() { int[] actual = new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] expected = new int[] { 8, 10, 5, 1, -1, 6, 9, 3, 0, 4, 2, 7 }; SortingUtils.Shuffle(actual); // Two collections are equivalent if they have the same elements in the same quantity, but in any order. CollectionAssert.AreEquivalent(expected, actual, "The shuffle did not shuffle correctly"); }
public void Shuffle_SuppliedRNG_Test() { // using rng with a fixed seed so we can compare this shuffle against a previous shuffle with the same seed. var random = new Random(1024); int[] actual = new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] expected = new int[] { 8, 10, 5, 1, -1, 6, 9, 3, 0, 4, 2, 7 }; SortingUtils.Shuffle(actual, random); CollectionAssert.AreEqual(expected, actual, "The shuffle did not produce the expected result"); }
public void AssertThatTypeProperlySortedIn(string columnName, string pageName, string attributeType, string sortOrder) { var page = new GenericEntityPage(pageName, _contextConfiguration); // Get original list var originalList = page.GetColumnContents(columnName); // Filter out non-alphanumeric contents except Date, Time, DateTime var sortingList = SortingUtils.FilterOutNonAlphanumeric(attributeType, originalList); switch (sortingList.Count) { case 0: Assert.Empty(sortingList); // When table content is all non-alphanumeric/non-date/times break; default: var sortedList = SortingUtils.AssertSorted(_contextConfiguration.CultureInfo, attributeType, sortingList, sortOrder); Assert.Equal(sortedList, sortingList, new EqualityListComparer <string>()); break; } }
public static void Sort <T>(IList <T> data, IComparer <T> comparer) { int length = data.Count; bool sorted = false; while (!sorted) { // Reset Sort Status sorted = true; for (int i = 1; i < length; i++) { // if this pair is out of order, swap them and remember something changed if (comparer.Compare(data[i - 1], data[i]) > 0) { SortingUtils.Swap(data, i - 1, i); sorted = false; } } // NOTE: Optimization, since each pass trough the array the last element is always in it's final place. We no longer need to check it. length--; } }
protected static void Quicksort(IList <UIComponent> elements, Comparison <UIComponent> comp, bool invert) => SortingUtils.Quicksort(elements, comp, invert);
protected static int NaturalCompare(string left, string right) => SortingUtils.NaturalCompare(left, right);
private void ReSort() { SortingUtils.Quicksort(mainPanel.components, getSortingMethod(m_LastSortCriterionLines), reverseOrder); mainPanel.Invalidate(); }