private void MethodComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var methodComboBox = MethodComboBox.SelectedItem; if (methodComboBox == null) { return; } if (methodComboBox.Equals(CocktailComboBox)) { _sortingMethod = SortingMethods.Cocktail; } else if (methodComboBox.Equals(InsertionComboBox)) { _sortingMethod = SortingMethods.Insertion; } else if (methodComboBox.Equals(MergeComboBox)) { _sortingMethod = SortingMethods.Merge; } else if (methodComboBox.Equals(SelectionComboBox)) { _sortingMethod = SortingMethods.Merge; } else { _sortingMethod = SortingMethods.Bubble; } }
public List <Product> GetCurrentProductsList(ProductContainer conteiner, SortingMethods sortingMethod = SortingMethods.Rating, bool ascending = false) { List <Product> currentProductsList = new List <Product>(); switch (conteiner) { case ProductContainer.Cart: throw new NotImplementedException("Currently not required"); case ProductContainer.WishList: //to do: capture names to another list, or smth like this int count = CountProductsInContainer(ProductContainer.WishList); for (int i = 1; i <= count; i++) { m_home.OpenWishlist(); SmallSleep(); Sort(sortingMethod, ascending); SmallSleep(); currentProductsList.Add(new Product(ProductContainer.WishList, i, m_home, m_driver)); } break; } return(currentProductsList); }
private void Sort(SortingMethods sortingMethod, bool ascending = false) { var element = m_driver.FindElement(By.XPath("//div[@class='row justify-content-end products-sort']//span[@class='ng-arrow-wrapper']")); element.Click(); SmallSleep(); var options = m_driver.FindElements(By.XPath("//div[@class='row']//div[@class='row justify-content-end products-sort']//div[@role='option']")); TestHelper.JSexecutorClick(options[(Int32)sortingMethod], m_driver); MidSleep(); var ascDscButton = m_driver.FindElement(By.XPath("//div[@class='row justify-content-end products-sort']//button[@class='btn btn-outline-secondary']/i")); string indicator = ascDscButton.GetAttribute("class"); if (indicator.Contains("-desc")) { if (ascending) { TestHelper.JSexecutorClick(ascDscButton, m_driver); } } else { if (!ascending) { TestHelper.JSexecutorClick(ascDscButton, m_driver); } } }
public void ValidateProductSorting(SortingMethods sortingMethod, bool ascending = false) { switch (sortingMethod) { case SortingMethods.Brand: var extractedList = GetCurrentProductsList(ProductContainer.WishList, sortingMethod, ascending); var expectedList = ascending ? extractedList.OrderBy(o => o.Brand, StringComparer.Ordinal) : extractedList.OrderByDescending(o => o.Brand, StringComparer.Ordinal); Assert.That(extractedList.SequenceEqual(expectedList)); break; case SortingMethods.Category: throw new NotImplementedException("This sorting type validation is not implemented yet"); case SortingMethods.Newest: throw new NotImplementedException("This sorting type validation is not implemented yet"); case SortingMethods.Price: extractedList = GetCurrentProductsList(ProductContainer.WishList, sortingMethod, ascending); expectedList = ascending ? extractedList.OrderBy(o => o.ProductPrice) : extractedList.OrderByDescending(o => o.ProductPrice); Assert.That(extractedList.SequenceEqual(expectedList)); break; case SortingMethods.Rating: extractedList = GetCurrentProductsList(ProductContainer.WishList, sortingMethod, ascending); expectedList = ascending ? extractedList.OrderBy(o => o.VotesCount) : extractedList.OrderByDescending(o => o.VotesCount); Assert.That(extractedList.SequenceEqual(expectedList)); break; default: break; } }
/// <summary> /// Sorting selected location, using selected method. /// </summary> /// <param name="sortLocation">Can take ProductContainer or ProductCategory</param> /// <param name="sortingMethod"></param> /// <param name="ascending">Optional parameter, default value = false - sorting is descending</param> public void SortProducts(Enum sortLocation, SortingMethods sortingMethod, bool ascending = false) { if (sortLocation is ProductContainer) { switch ((ProductContainer)sortLocation) { case ProductContainer.Cart: throw new NotSupportedException("Currently sorting is not supported in Cart"); case ProductContainer.WishList: m_home.OpenWishlist(); SmallSleep(); Sort(sortingMethod, ascending); break; default: return; } } else if (sortLocation is ProductCategories) { throw new NotSupportedException("Currently sorting in categories is not supported"); } else { return; } }
void Scenary2() { sm = new SortingMethods(); array = new int[100000]; array2 = new int[100000]; array = generate(array); array2 = array; sm.BubbleSort(array); }
public void ToggleSortBySource(bool value) { Debug.Log("On Button Sort-by-Source" + value); if (CurrSortMethod != SortingMethods.SOURCE || value) { // Clear the other tags foreach (var tagObj in nameTagDict.Values) { tagObj.SetActive(false); } foreach (var tagObj in dateTagDict.Values) { tagObj.SetActive(false); } // sort by source int rowID = 0; nextNoteX = notePadding; // -currBoardWidth / 2; nextNoteY = -notePadding; // currBoardHeight / 2; // Create the first tag currTag = ""; foreach (var key in sourceNoteDict.Keys) { foreach (var obj in sourceNoteDict[key]) { //if (nextNoteX >= currBoardWidth / 2 || (currTag.Length > 0 && obj.Source != currTag)) if (nextNoteX >= currBoardWidth || (currTag.Length > 0 && obj.Source != currTag)) { // Move to the new line. nextNoteX = notePadding;// -currBoardWidth / 2; nextNoteY -= avgNoteHeight; } if (obj.Source != currTag) { currTag = obj.Source; AddTag(currTag, sourceTagDict); } float newX = nextNoteX + obj.width / 2; float newY = nextNoteY - obj.height / 2; Vector3 src = obj.gameObject.transform.position; obj.currTransform.localPosition = new Vector3(newX, newY, -0.01f); nextNoteX += obj.width + notePadding; StartCoroutine(obj.SlowMove(src, obj.gameObject.transform.position)); } rowID++; } CurrSortMethod = SortingMethods.SOURCE; } }
void Scenary6() { sm = new SortingMethods(); array = new int[100000]; array2 = new int[100000]; for (int i = 100000; i > 0; i--) { array[i - 1] = i; } array2 = array; sm.BubbleSort(array); }
void Scenary4() { sm = new SortingMethods(); array = new int[10000]; array2 = new int[10000]; for (int i = 0; i < array.Length; i++) { array[i] = i + 1; } array2 = array; sm.BubbleSort(array); }
/// <summary> /// Sort by time, if current method is not 'time'. /// </summary> /// <param name="value">If value is true, then sort anyway.</param> public void ToggleSortByTime(bool value) { Debug.Log("On Button Sort-by-Time" + value); if (CurrSortMethod != SortingMethods.TIME || value) { // Clear the other tags foreach (var tagObj in nameTagDict.Values) { tagObj.SetActive(false); } foreach (var tagObj in sourceTagDict.Values) { tagObj.SetActive(false); } // sort by time nextNoteX = notePadding; // -currBoardWidth / 2; nextNoteY = -notePadding; // currBoardHeight / 2; currTag = ""; foreach (var obj in noteObjList) { //if (nextNoteX + obj.width / 2 > currBoardWidth / 2 || (currTag.Length > 0 && obj.CreateDate != currTag)) if (nextNoteX + obj.width / 2 > currBoardWidth || (currTag.Length > 0 && obj.CreateDate != currTag)) { // Move to the new line. nextNoteX = notePadding;// -currBoardWidth / 2; nextNoteY -= avgNoteHeight; } if (obj.CreateDate != currTag) { currTag = obj.CreateDate; AddTag(currTag, dateTagDict); } float newX = nextNoteX + obj.width / 2; float newY = nextNoteY - obj.height / 2; Vector3 src = obj.gameObject.transform.position; obj.currTransform.localPosition = new Vector3(newX, newY, -0.01f); nextNoteX += obj.width + notePadding; StartCoroutine(obj.SlowMove(src, obj.gameObject.transform.position)); } CurrSortMethod = SortingMethods.TIME; } }
static void Main(string[] args) { while (true) { int[] inputArray = null; Console.WriteLine("Choose sorting method: \n" + "1 - Merge sort \n" + "2 - Quick sort"); var method = Console.ReadKey(); switch (method.KeyChar) { case '1': { Console.WriteLine(); FillArray(ref inputArray); Console.WriteLine("Original array:"); PrintArray(inputArray); SortingMethods.MergeSort(inputArray); Console.WriteLine("Sorted array: "); PrintArray(inputArray); break; } case '2': { Console.WriteLine(); FillArray(ref inputArray); Console.WriteLine("Original array:"); PrintArray(inputArray); SortingMethods.QuickSort(inputArray); Console.WriteLine("Sorted array: "); PrintArray(inputArray); break; } default: { Console.WriteLine(); Console.WriteLine("Wrong choice!"); continue; } } } }
private static void TestInvertedOrder(int count) { var arr = new RouteCard[count]; for (int i = count; i > 0; i--) { arr[i - 1] = new RouteCard { From = i.ToString(), To = (i - 1).ToString() }; } var result = SortingMethods.Sort(arr); for (int i = count; i > 0; i--) { Assert.AreEqual(arr[count - i], result[i - 1]); } }
private static void TestDirectOrder(int count) { var arr = new RouteCard[count]; for (int i = 0; i < count; i++) { arr[i] = new RouteCard { From = i.ToString(), To = (i + 1).ToString() }; } var result = SortingMethods.Sort(arr); for (int i = 0; i < count; i++) { Assert.AreEqual(arr[i], result[i]); } }
private static void TestRandomOrder(int count) { var arr = new RouteCard[count]; for (int i = 0; i < count; i++) { arr[i] = new RouteCard { From = i.ToString(), To = (i + 1).ToString() }; } //Для того, чтобы не нарушать условие воспроизводимости теста, зафиксируем зерно рандома var rand = new Random(42); arr = arr.OrderBy(x => rand.Next()).ToArray(); var result = SortingMethods.Sort(arr); //Требуемый порядок нам не известен, поэтому проверим соответствует ли массив условиям сортировки for (int i = 0; i < count - 1; i++) { Assert.AreEqual(result[i].To, result[i + 1].From); } }
public void QuickSortTest() { int[] array = { 24, 16, 54, -4, 3, 47, 93, 101, 255, -34, -2019 }; SortingMethods.Quicksort(array); Assert.AreEqual(new int[] { -2019, -34, -4, 3, 16, 24, 47, 54, 93, 101, 255 }, array); }
public void CheckMergeSortOnEmpty() => Assert.Throws <ArgumentException>(() => SortingMethods.Mergesort(new int[] { }));
public void CheckIsSorted_InsertionSortsArray_True() { int[] num = new int[] { 4, 3, 1, 2, 0 }; int[] num2 = SortingMethods.InsertionSort(num); Assert.AreEqual(0, num2[0]); }
public void CheckIsSorted_BubbleSortsArray_True() { int[] num = new int[] { 4, 3, 1, 2 }; int[] num2 = SortingMethods.BubbleSort(num); Assert.AreEqual(3, num2[2]); }
public void CheckQuickSortOnNull() => Assert.Throws <ArgumentNullException>(() => SortingMethods.Quicksort(null));
public void CheckIsSorted_MergeSortsArray_True() { int[] num = new int[] { 4, 3, 1, 2, 0, 77, 99, 27381, 28, 921873, 2487, 4239, 92, 11, 93, 111 }; int[] num2 = SortingMethods.MergeSort(num); Assert.AreEqual(4, num2[8]); }
public void CheckMergeSortOnNull() => Assert.Throws <ArgumentNullException>(() => SortingMethods.Mergesort(null));