Exemple #1
0
 public void Sorting_Array_By_QuickSort_Success()
 {
     int[] actual   = new int[] { 5, 8, -1, 4, 6, -2, 9, 7, 1, -3, 3, 2, 0 };
     int[] expected = new int[] { -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     Sortings.QuickSorting(actual);
     CollectionAssert.AreEqual(actual, expected);
 }
Exemple #2
0
        static int[] GenerateRandomArray(int length, Sortings function)
        {
            int[]  randoms = new int[length];
            Random factory = new Random();

            for (int i = 0; i < randoms.Length; i++)
            {
                randoms[i] = factory.Next(MIN_RANDOM, MAX_RANDOM + 1);
            }


            switch (function)
            {
            case Sortings.Insertion:
            {
                InsertionSort(randoms);
                break;
            }

            case Sortings.Quick:
            {
                QuickSort(randoms);
                break;
            }
            }
            return(randoms);
        }
Exemple #3
0
 public void Sorting_SipleArray_Success()
 {
     int[] actual   = { 1 };
     int[] expected = { 1 };
     Sortings.QuickSorting(actual);
     CollectionAssert.AreEqual(actual, expected);
 }
Exemple #4
0
        public void QuickSort_NullArray()
        {
            // Arrange
            int[] array = null;

            // Act
            Sortings.QuickSort(array);
        }
Exemple #5
0
        public void MergeSort_TestArraySort_ExpectedArray()
        {
            int[] testArray     = { 7, -2, 1, 4, 0, 9, 5, 3, 1, 8 };
            int[] expectedArray = { -2, 0, 1, 1, 3, 4, 5, 7, 8, 9 };

            Sortings.MergeSort(testArray);
            CollectionAssert.AreEqual(expectedArray, testArray);
        }
Exemple #6
0
        public void MergeSort_NullArray()
        {
            // Arrange
            int[] array = null;

            // Act
            Sortings.MergeSort(array);
        }
Exemple #7
0
        public Query <T> OrderBy(string propertyName)
        {
            Sortings.Add(new Sorting
            {
                PropertyName = propertyName,
                Direction    = SortDirection.Ascending
            });

            return(this);
        }
Exemple #8
0
        public Query <T> OrderByDescending <TKey>(Expression <Func <T, TKey> > keySelector)
        {
            Sortings.Add(new Sorting
            {
                PropertyName = GetPropertyPath(keySelector),
                Direction    = SortDirection.Descending
            });

            return(this);
        }
Exemple #9
0
 private void FillSorts(HtmlNodeCollection sorts)
 {
     foreach (var sort in sorts)
     {
         var aTag = sort.FirstChild;
         var text = aTag.InnerText;
         var attr = HttpUtility.UrlEncode(aTag.GetAttributeValue("value", string.Empty));
         Sortings.Add(text, attr);
     }
 }
Exemple #10
0
        public void MergeSort_IntArrayOf5El()
        {
            // Arrange
            var expexted = new[] { 1, 2, 3, 4, 5 };
            var actual   = new[] { 3, 1, 2, 5, 4 };

            // Act
            Sortings.MergeSort(actual);

            // Assert
            Assert.IsTrue(expexted.SequenceEqual(actual));
        }
Exemple #11
0
        public void MergeSort_IntArrayOfNegativeAndBigEl()
        {
            // Arrange
            var expexted = new[] { int.MinValue, -333, 0, 1, 9999, int.MaxValue };
            var actual   = new[] { 9999, int.MaxValue, -333, int.MinValue, 0, 1 };

            // Act
            Sortings.MergeSort(actual);

            // Assert
            Assert.IsTrue(expexted.SequenceEqual(actual));
        }
Exemple #12
0
        public void Sorting_Array_By_Quicksort_In_Huge_Size()
        {
            Random rnd = new Random();

            int[] actual   = new int[10000000];
            int[] expected = actual;
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = rnd.Next();
            }
            Sortings.QuickSorting(actual);
            CollectionAssert.AreEqual(actual, expected);
        }
Exemple #13
0
            static void Main(String[] args)
            {
                Console.WriteLine("----------------------");

                int[] intUnsorted = Utility.getInputArray();

                Console.WriteLine("----Unsorted Array----");

                int[] intSorted = Sortings.Sort(intUnsorted);

                Console.WriteLine();
                Console.WriteLine("----Sorted Array----");
                Utility.printArray(intSorted);

                Console.ReadLine();
            }
Exemple #14
0
        public List <Place> Search(string name = null, int type = -1, Sortings order = Sortings.Default)
        {
            var result = GetAllPlaces()
                         .Where(p => (string.IsNullOrEmpty(name) ||
                                      p.Name.ToLower().Contains(name.ToLower()) &&
                                      (type < 0 || p.Type == type))).ToList();

            if (order == Sortings.ByName)
            {
                return(result.OrderBy(p => p.Name).ToList());
            }
            if (order == Sortings.ByRating)
            {
                return(result.OrderBy(p => p.AverageMark).ToList());
            }
            return(result);
        }
Exemple #15
0
        public void MergeSort_LargeArray_ExtectedArray()
        {
            int    minPossibleValue = 0;
            int    maxPossibleValue = 1000000;
            Random randNum          = new Random();

            int[] largeTestArray = new int[Int32.MaxValue / 10000];
            for (int i = 0; i < largeTestArray.Length; i++)
            {
                largeTestArray[i] = randNum.Next(minPossibleValue, maxPossibleValue);
            }

            int[] expectedArray = largeTestArray;
            Array.Sort(expectedArray);

            Sortings.MergeSort(largeTestArray);
            CollectionAssert.AreEqual(expectedArray, largeTestArray);
        }
Exemple #16
0
        static void RunIteration(int length, Sortings function)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var randoms = GenerateRandomArray(length, function);
            var hist    = GenerateHistogram(randoms);

            stopwatch.Stop();

            Console.Write("{0,10},{1,10},", length, stopwatch.ElapsedMilliseconds);
            for (int i = MIN_RANDOM; i < MAX_RANDOM + 1; i++)
            {
                Console.Write("{0,10},", hist.GetValueOrDefault(i, 0));
            }

            Console.WriteLine();
        }
        public LinqToSolrQuery AddSorting(Expression field, SolrSortTypes order)
        {
            Sortings.Add(LinqToSolrSort.Create(field, order));

            return(this);
        }
Exemple #18
0
 public void QuickSort_Null_ArgumentNullException()
 {
     Sortings.QuickSort(null);
 }
Exemple #19
0
 public void QuickSort_EmptyArray_ArgumentNullException()
 {
     Sortings.QuickSort(new int[] { });
 }
Exemple #20
0
 public void MergeSort_Null_ArgumentNullException()
 {
     Sortings.MergeSort(null);
 }
Exemple #21
0
 public void MergeSort_EmptyArray_ArgumentNullException()
 {
     Sortings.MergeSort(new int[] { });
 }
Exemple #22
0
 public void QuickSort_With_Throwing_ArgumentNullException()
 {
     int[] actual = null;
     Sortings.MergeSorting(actual);
 }