Beispiel #1
0
        public void searchMember()
        {
            string input;

            do
            {
                Console.Write("\t\t\t\tInput: ");
                input = Console.ReadLine().Trim();
            } while (String.IsNullOrEmpty(input));

            bool longInput = long.TryParse(input, out long result);

            if (longInput)
            {
                var sortedList   = QuickSorter.QuickSort(Members.ToArray(), 0, Members.Count - 1, o => o.SocialSecurityNr);
                var searchResult = LinearSearch(sortedList, o => o.SocialSecurityNr, result);
                UI.PrintMembers("\t\tSearch Result (Social Security Number)", searchResult);
            }
            else
            {
                var sortedList   = QuickSorter.QuickSort(Members.ToArray(), 0, Members.Count - 1, o => o.LastName);
                var searchResult = LinearSearch(sortedList, o => o.LastName.ToLower(), input.ToLower());
                UI.PrintMembers("\t\t    Search Result (Last Name)", searchResult);
            }
        }
        public void QuickSortTest()
        {
            int[] arr = { 1, 2, 8, 7, 4, 3, 5, 6 };
            var   qs  = new QuickSorter();

            qs.QuickSort(arr);
            Assert.AreEqual(arr[7], 8);
        }
Beispiel #3
0
        public void SortByLastName()
        {
            Console.Clear();
            UI.PrintMembers("\t\t\t    Unsorted", Members);
            var sortedList = QuickSorter.QuickSort(Members.ToArray(), 0, Members.Count - 1, o => o.LastName);

            UI.PrintMembers("\t\t\t    Sorted (Last Name)", sortedList.ToList());
        }
Beispiel #4
0
        public void SortByEldest()
        {
            Console.Clear();
            UI.PrintMembers("\t\t\t    Unsorted", Members);
            var sortedList = QuickSorter.QuickSort(Members.ToArray(), 0, Members.Count - 1, o => o.SocialSecurityNr);

            UI.PrintMembers("\t\t\t    Sorted (Age)", sortedList.ToList());
        }
Beispiel #5
0
        public void Test1()
        {
            var list = new List <int> {
                5, 8, 4, 1, 2, 6, 4, 7, 9, 2
            };

            QuickSorter.QuickSort <int>(list, Comparer <int> .Default);
        }
Beispiel #6
0
        public void TestQuickSort2()
        {
            QuickSorter qs = new QuickSorter();

            int[] arr = new int[] { };
            qs.QuickSort(ref arr, 0, arr.Length - 1);

            arr = new int[] { 1 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1 });

            arr = new int[] { 1, 1, 1, 1, 1, 1 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1, 1, 1, 1, 1, 1 });

            arr = new int[] { 14, 16, 5, 9, 2, 7, 1, 13 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1, 2, 5, 7, 9, 13, 14, 16 });

            arr = new int[] { 1, 1, 2, 3, 4, 5 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1, 1, 2, 3, 4, 5 });

            arr = new int[] { 5, 3, 2, 7, 1, 6, 4, 9 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1, 2, 3, 4, 5, 6, 7, 9 });

            arr = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
            qs.QuickSort(ref arr, 0, arr.Length - 1);
            arr.AreEqual(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
        }
Beispiel #7
0
        public void ShouldSortMultipleItems()
        {
            var sorter = new QuickSorter <int>();

            int[] items = { 8, 3, 4, 12, 73, 1, 3, 4, 5 };
            sorter.QuickSort(items);

            Assert.AreEqual(new int[] { 1, 3, 3, 4, 4, 5, 8, 12, 73 }, items);
        }
Beispiel #8
0
        public void ShouldSortTwoItems()
        {
            var sorter = new QuickSorter <int>();

            int[] items = { 8, 3 };
            sorter.QuickSort(items);

            Assert.AreEqual(new int[] { 3, 8 }, items);
        }
Beispiel #9
0
        public void ShouldSortEmptyArray()
        {
            var sorter = new QuickSorter <int>();

            int[] items = { };
            sorter.QuickSort(items);

            Assert.IsEmpty(items);
        }
Beispiel #10
0
        public void CanPerformQuickSort()
        {
            var array       = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 };
            var arrayToSort = new int[] { 2, 5, -4, 11, 0, 18, 22, 67, 51, 6 };
            var sorter      = new QuickSorter();

            sorter.QuickSort(arrayToSort);

            Assert.AreEqual(array.Length, arrayToSort.Length);

            var previousItem = array.Min() - 1;

            foreach (var item in arrayToSort)
            {
                Assert.IsTrue(array.Contains(item));
                Assert.IsTrue(previousItem < item);

                previousItem = item;
            }
        }
        public static void Test()
        {
            int TestTimes = 1000;

            while (--TestTimes > 0)
            {
                Array = new byte[Random.Next(50)];

                Random.NextBytes(Array);

                Console.Write("\r\nBefore Sort : ");

                foreach (byte Data in Array)
                {
                    Console.Write(Data.ToString() + '\t');
                }

                QuickSorter.QuickSort(0, Array.Length - 1, Compare, Swap);

                Console.Write("\r\nAfter Sort : ");

                foreach (byte Data in Array)
                {
                    Console.Write(Data.ToString() + '\t');
                }

                if (Array.Length <= 1)
                {
                    continue;
                }

                for (int Idx = 0; Idx < Array.Length - 1; Idx++)
                {
                    if (Array[Idx] > Array[Idx + 1])
                    {
                        Console.Write("\r\nSort Error");
                    }
                }
            }
        }
Beispiel #12
0
 public int[] Quick_Sort_Test(int[] array)
 {
     QuickSorter.QuickSort(array);
     return(array);
 }
Beispiel #13
0
 public void SortByQuick()
 {
     mergeSortResult    = quickSorter.QuickSort(ref mergeTestArray, 0, mergeTestArray.Length - 1);
     resultDisplay.text = mergeSortResult.ToString();
 }
Beispiel #14
0
        public void SortIWrote_Check_Sorting_Behavior()
        {
            int[] unsortedInts = { 6, 12, 8, 2, 9 };

            QuickSorter.QuickSort(unsortedInts, 0, 4);
        }
Beispiel #15
0
 public void TestInOrder(int[] value, int[] expected)
 {
     Assert.AreEqual(expected, QuickSorter.QuickSort(value));
 }