public void TestWithAnEmptyCollection()
 {
     List<int> collection = new List<int>();
     Quicksorter<int> sorter = new Quicksorter<int>();
     sorter.Sort(collection);
     Assert.AreEqual(0, collection.Count);
 }
Example #2
0
        public void QuickSortNullTest()
        {
            IList <int>       arr    = null;
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(arr);
        }
Example #3
0
        public void QuickSortZeroTest()
        {
            IList <int>       arr    = new List <int>();
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(arr);
        }
        public void QuickSortTestWithOneMemberArray()
        {
            Quicksorter<int> quicksorter = new Quicksorter<int>();
            IList<int> list = new List<int>() { 1, };
            IList<int> sortedList = new List<int>() { 1, };

            quicksorter.Sort(list);
            Assert.AreEqual(string.Join(",", sortedList), string.Join(",", list));
        }
        public void QuickSortTestWithFilledArray()
        {
            Quicksorter<int> quicksorter = new Quicksorter<int>();
            IList<int> list = new List<int>() { 9, 3, 2, 1, 4, 6, 5, 0, 8, 7 };
            IList<int> sortedList = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            quicksorter.Sort(list);
            Assert.AreEqual(string.Join(",", sortedList), string.Join(",", list));
        }
        public void ReversedNumberSortTest()
        {
            List<int> arrayToSort = new List<int>() { 5, 4, 3, 2, 1 };
            Quicksorter<int> quickSorter = new Quicksorter<int>();

            List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 };

            quickSorter.Sort(arrayToSort);

            CollectionAssert.AreEqual(expectedArray, arrayToSort);
        }
 private void PopulateAndSort(Quicksorter <int> quicksorter)
 {
     quicksorter.Add(4);
     quicksorter.Add(5);
     quicksorter.Add(8);
     quicksorter.Add(6);
     quicksorter.Add(3);
     quicksorter.Add(7);
     quicksorter.Add(9);
     quicksorter.Sort();
 }
        public void AlreadySortedNumsTest()
        {
            List<int> quickSorter = new List<int>() { 1, 2, 3, 4, 5 };
            Quicksorter<int> mergeSorter = new Quicksorter<int>();

            List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 };

            mergeSorter.Sort(quickSorter);

            CollectionAssert.AreEqual(expectedArray, quickSorter);
        }
        public void TestWithASingleItem()
        {
            List<int> collection = new List<int>();
            collection.Add(3);

            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(3, collection[0]);
        }
        public void SimpleQuickSortTest()
        {
            List<int> arrayToSort = new List<int>() { 2, 5, 3, 1, 4 };
            Quicksorter<int> quickSorter = new Quicksorter<int>();

            List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 };

            quickSorter.Sort(arrayToSort);

            CollectionAssert.AreEqual(expectedArray, arrayToSort);
        }
        public void TestSortLengthOfCollection()
        {
            List<int> collection = new List<int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 
            };
            int count = collection.Count;
            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            Assert.AreEqual(count, collection.Count);
        }
Example #12
0
        public void SortShould_NotThrowIfTheCollectionIsEmpty_AndReturnEmptyCollection()
        {
            // Arange
            var sorter     = new Quicksorter <string>();
            var collection = new List <string>(0);

            // Act
            sorter.Sort(collection);

            // Assert
            Assert.AreEqual("", string.Join(", ", collection));
        }
        public void TestSortLengthOfCollection()
        {
            List <int> collection = new List <int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23
            };
            int count = collection.Count;
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(collection);

            Assert.AreEqual(count, collection.Count);
        }
        public void TestWithTwoItems()
        {
            List<int> collection = new List<int>();
            collection.Add(3);
            collection.Add(0);

            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            Assert.AreEqual(2, collection.Count);
            Assert.AreEqual(0, collection[0]);
            Assert.AreEqual(3, collection[1]);
        }
Example #15
0
        public void SortShould_SortThePassedCollectionOfStrings()
        {
            // Arange
            var sorter     = new Quicksorter <string>();
            var collection = new List <string>()
            {
                "2", "1", "4", "5", "6", "3"
            };
            var result = "1, 2, 3, 4, 5, 6";

            // Act
            sorter.Sort(collection);

            // Assert
            Assert.AreEqual(result, string.Join(", ", collection));
        }
Example #16
0
        public void SortShould_SortThePassedCollectionOfIntegers()
        {
            // Arange
            var sorter     = new Quicksorter <int>();
            var collection = new List <int>()
            {
                2, 1, 4, 5, 6, 3
            };
            var result = "1, 2, 3, 4, 5, 6";

            // Act
            sorter.Sort(collection);

            // Assert
            Assert.AreEqual(result, string.Join(", ", collection));
        }
Example #17
0
        public void QuickSortSortedTest()
        {
            var arr = new List <int>()
            {
                0, 11, 22, 33, 101, 101
            };
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(arr);
            var expected = new List <int>()
            {
                0, 11, 22, 33, 101, 101
            };

            CollectionAssert.AreEqual(arr, expected);
        }
        public void TestSortIsSortedWithListSort()
        {
            List<int> collection = new List<int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 
            };
            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            List<int> collection2 = new List<int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 
            };
            collection2.Sort();

            CollectionAssert.AreEqual(collection2, collection);
        }
        public void TestWithOddNumberOfItems()
        {
            List<int> collection = new List<int>();
            collection.Add(3);
            collection.Add(0);
            collection.Add(11);
            collection.Add(-3);
            collection.Add(5);
            collection.Add(0);
            collection.Add(4);

            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            Assert.AreEqual(7, collection.Count);
            Assert.IsTrue(SortableCollection<int>.IsSorted(collection));
        }
        public void TestSortIsSortedWithListSort()
        {
            List <int> collection = new List <int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23
            };
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(collection);

            List <int> collection2 = new List <int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23
            };

            collection2.Sort();

            CollectionAssert.AreEqual(collection2, collection);
        }
        public void TestSortIsSortedWithCheck()
        {
            List<int> collection = new List<int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 
            };
            Quicksorter<int> sorter = new Quicksorter<int>();
            sorter.Sort(collection);

            bool isSorted = true;
            for (int i = 0; i < collection.Count - 1; i++)
            {
                if (collection[i] > collection[i + 1])
                {
                    isSorted = false;
                }
            }

            Assert.IsTrue(isSorted);
        }
        public void TestSortIsSortedWithCheck()
        {
            List <int> collection = new List <int>()
            {
                3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23
            };
            Quicksorter <int> sorter = new Quicksorter <int>();

            sorter.Sort(collection);

            bool isSorted = true;

            for (int i = 0; i < collection.Count - 1; i++)
            {
                if (collection[i] > collection[i + 1])
                {
                    isSorted = false;
                }
            }

            Assert.IsTrue(isSorted);
        }
Example #23
0
        public override IEnumerable <TElement> Sort(IEnumerable <TElement> collection, IComparer <TElement> comparer, bool parallel)
        {
            var quicksorter = new Quicksorter(collection, comparer, parallel);

            return(quicksorter.Sort());
        }
 public void TestWithANullCollection()
 {
     List<int> collection = null;
     Quicksorter<int> sorter = new Quicksorter<int>();
     sorter.Sort(collection);
 }