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;
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        /// <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;
            }
        }
Exemplo n.º 6
0
        void Scenary2()
        {
            sm     = new SortingMethods();
            array  = new int[100000];
            array2 = new int[100000];
            array  = generate(array);

            array2 = array;
            sm.BubbleSort(array);
        }
Exemplo n.º 7
0
    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;
        }
    }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
    /// <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;
        }
    }
Exemplo n.º 11
0
        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;
                }
                }
            }
        }
Exemplo n.º 12
0
        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]);
            }
        }
Exemplo n.º 13
0
        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]);
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 public void CheckMergeSortOnEmpty() => Assert.Throws <ArgumentException>(() => SortingMethods.Mergesort(new int[] { }));
Exemplo n.º 17
0
 public void CheckIsSorted_InsertionSortsArray_True()
 {
     int[] num  = new int[] { 4, 3, 1, 2, 0 };
     int[] num2 = SortingMethods.InsertionSort(num);
     Assert.AreEqual(0, num2[0]);
 }
Exemplo n.º 18
0
 public void CheckIsSorted_BubbleSortsArray_True()
 {
     int[] num  = new int[] { 4, 3, 1, 2 };
     int[] num2 = SortingMethods.BubbleSort(num);
     Assert.AreEqual(3, num2[2]);
 }
Exemplo n.º 19
0
 public void CheckQuickSortOnNull() => Assert.Throws <ArgumentNullException>(() => SortingMethods.Quicksort(null));
Exemplo n.º 20
0
 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]);
 }
Exemplo n.º 21
0
 public void CheckMergeSortOnNull() => Assert.Throws <ArgumentNullException>(() => SortingMethods.Mergesort(null));