示例#1
0
    static void Main()
    {
        var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
        Console.WriteLine("All items before sorting:");
        Console.WriteLine(collection);

        Console.WriteLine("SelectionSorter result:");
        collection.Sort(new SelectionSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Quicksorter result:");
        collection.Sort(new Quicksorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("MergeSorter result:");
        collection.Sort(new MergeSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Linear search 101:");
        Console.WriteLine(collection.LinearSearch(101));

        Console.WriteLine("Binary search 101:");
        Console.WriteLine(collection.BinarySearch(101));

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        Console.WriteLine(collection);

        Console.WriteLine("Shuffle again:");
        collection.Shuffle();
        Console.WriteLine(collection);
    }
        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("BubbleSorter result:");
            collection.Sort(new BubbleSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("InsertionSorter result:");
            collection.Sort(new InsertionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("QuickSorter result:");
            collection.Sort(new QuickSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            /*Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();*/
        }
 public void Test1SectionSortMethod()
 {
     var collection = new SortableCollection<int>(new[] { 22, 13 });
     collection.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { 13, 22 });
     Assert.Equals(collection,testCollection);
 }
 public void Test3SectionSortMethod()
 {
     var collection1 = new SortableCollection<string>(new[] { "aaaa", "cccc", "dddd", "cccc", "caaa", "aacc", "bbdd", "ccff", "eerr", "rrtt", "assdd" });
     collection1.Sort(new SelectionSorter<string>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
        public void TestSelectionSortingWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new SelectionSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting");
        }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collectionToShuffle = new SortableCollection<int>(1, 2, 3, 4, 5);
            Console.WriteLine("Before shufflin` " + collectionToShuffle);
            collectionToShuffle.Shuffle();
            Console.WriteLine("After shufflin` " + collectionToShuffle);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);
        }
        public void MergeSortShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new MergeSorter<int>());

            Assert.AreEqual(0, collection.Items.Count, "Collection is not empty after sorting!");
        }
 public void SelectionSorterTestWithOneElement()
 {
     SortableCollection<int> collection = new SortableCollection<int>(new int[] { 5 });
     collection.Sort(new SelectionSorter<int>());
     Assert.AreEqual(1, collection.Items.Count);
     Assert.AreEqual(5, collection.Items[0]);
 }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);

            collectionToSort.Sort(new BucketSorter { Max = MaxValue });
            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
            Console.WriteLine(collection);

            collection.Shuffle();
            Console.WriteLine(collection);

            //collection.Sort(new Quicksorter<int>());
            //Console.WriteLine(collection);
        }
        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            // !!!!!!!!!!!!!! collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);

            Console.WriteLine(collection.InterpolationSearch(0));
        }
示例#11
0
        public void TestSortWithMultipleElementsMultipleTimes()
        {
            const int NumberOfAttempts = 10000;
            const int MaxNumberOfElements = 1000;

            for (int i = 0; i < NumberOfAttempts; i++)
            {
                var numberOfElements = Random.Next(0, MaxNumberOfElements + 1);

                List<int> originalElements = new List<int>(MaxNumberOfElements);

                for (int j = 0; j < numberOfElements; j++)
                {
                    originalElements.Add(Random.Next(int.MinValue, int.MaxValue));
                }

                var collection = new SortableCollection<int>(originalElements);

                originalElements.Sort();
                collection.Sort(TestSorter);

                CollectionAssert.AreEqual(
                    originalElements,
                    collection.ToArray(),
                    "Sort method should sort the elements in ascending order.");
            }
        }
 public void Test2SectionSortMethod()
 {
     var collection1 = new SortableCollection<int>(new[] { 22, 13, 23, 45, -55, 90, 100, 101, -12, 55, 44 });
     collection1.Sort(new SelectionSorter<int>());
     var testCollection = new SortableCollection<int>(new[] { -55, -12, 13, 22, 23, 44, 45, 55, 90, 100, 101 });
     Assert.Equals(testCollection, collection1);
 }
 public void TestBinarySearchResultIsNotContained()
 {
     int[] input = { -1, 5, 8, 3, 4, 67, -9, 3, 9, 4 };
     SortableCollection<int> sortableCol = new SortableCollection<int>(input);
     sortableCol.Sort(new MergeSorter<int>());
     bool containsItem = sortableCol.BinarySearch(0);
     Assert.IsFalse(containsItem);
 }
 public void TestLinearSearchResultIsRandom()
 {
     int[] input = { -1, 5, 8, 3, 4, 67, -9, 3, 9, 4 };
     SortableCollection<int> sortableCol = new SortableCollection<int>(input);
     sortableCol.Sort(new MergeSorter<int>());
     bool containsItem = sortableCol.LinearSearch(-9);
     Assert.IsTrue(containsItem);
 }
 public void ShouldSortCorrectlySortedCollection()
 {
     var collection = new SortableCollection<int>(new[] { 1, 2, 3, 4, 5, 6, 7 });
     var expectedCollection = new List<int>(collection.Items);
     expectedCollection.Sort();
     collection.Sort(new SelectionSorter<int>());
     CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
 }
        public void LinearSearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection<int>();
            collection.Sort(new MergeSorter<int>());
            var found = collection.LinearSearch(21);

            Assert.IsFalse(found, "Element is found in empty collection!");
        }
 public void ShouldSortCorrectlyOnlyNegativeValues()
 {
     var collection = new SortableCollection<double>(new[] { -1.4, -8.6, -2, -13.1, -13.2, -55, -55, -55.1, -55.01 });
     var expectedCollection = new List<double>(collection.Items);
     expectedCollection.Sort();
     collection.Sort(new SelectionSorter<double>());
     CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
 }
        public void BinarySearchShouldWorkCorrectlyWhenSearchedElementIsNotFound()
        {
            var collection = new SortableCollection<int>(new int[] { 6, 1, 4, 2, 3, -5, 8 });
            collection.Sort(new MergeSorter<int>());
            var found = collection.BinarySearch(21);

            Assert.IsFalse(found, "Element is found in collection!");
        }
        public void BinarySearchItemFound()
        {
            var searchCollection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 122, 22, 33, 11, 3445667, 1233, 123, 101 });

            searchCollection.Sort(new Quicksorter<int>()); 

            Assert.IsTrue(searchCollection.BinarySearch(11));
        }
        public void BinarySearchItemNotFound()
        {
            var searchCollection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 122, 22, 33, 11, 3445667, 1233, 123, 101 });

            searchCollection.Sort(new SelectionSorter<int>()); 

            Assert.IsFalse(searchCollection.BinarySearch(66));
        }
 public void TestBinarySearchResultIsLast()
 {
     int[] input = { 8, 5, 8, 3, 4, 67, 9, 3, 9, -4 };
     SortableCollection<int> sortableCol = new SortableCollection<int>(input);
     sortableCol.Sort(new MergeSorter<int>());
     bool containsItem = sortableCol.BinarySearch(-4);
     Assert.IsTrue(containsItem);
 }
        public void TestWithOddNumberOfItemsFoundAtMiddlePosition()
        {
            SortableCollection<int> collection = new SortableCollection<int>(new int[] { 4, 3, -2, 11, 16, 0, 1 });
            collection.Sort(new MergeSorter<int>());

            bool isFound = collection.BinarySearch(3);
            Assert.IsTrue(isFound);
        }
        public void TestWithTwoItemsNotFound()
        {
            SortableCollection<int> collection = new SortableCollection<int>(new int[] { 4, 3 });
            collection.Sort(new MergeSorter<int>());

            bool isFound = collection.BinarySearch(0);
            Assert.IsFalse(isFound);
        }
        public void BinarySearchShouldWorkCorrectlyWhenSearchedElementIsLast()
        {
            var collection = new SortableCollection<int>(new int[] { 6, 1, 4, 2, 3, 21, -5, 8 });
            collection.Sort(new MergeSorter<int>());
            var found = collection.BinarySearch(8);

            Assert.IsTrue(found, "Element is not found in collection!");
        }
 public void ShouldSortCorrectlyDoubles()
 {
     var collection = new SortableCollection<double>(new[] { 1.4, -8.6, 2, 13.1, 13.2, 55, 55, 55.1, 55.01 });
     var expectedCollection = new List<double>(collection.Items);
     expectedCollection.Sort();
     collection.Sort(new SelectionSorter<double>());
     CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
 }
        public void SortReversedCollectionTest()
        {
            SortableCollection<int> collection =
                 new SortableCollection<int>(GenerateReversed(100));

            collection.Sort(sorter);

            Assert.IsTrue(IsSorted(collection.Items));
        }
示例#27
0
        internal static void Main(string[] args)
        {
            var sw = new Stopwatch();

            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            sw.Start();
            collection.Sort(new SelectionSorter<int>());
            Console.WriteLine("Time : {0}",sw.ElapsedTicks);
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("Quicksorter result:");
            sw.Restart();
            collection.Sort(new Quicksorter<int>());
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            sw.Restart();
            collection.Sort(new MergeSorter<int>());
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Linear search 101:");
            sw.Restart();
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            sw.Restart();
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            sw.Restart();
            collection.Shuffle();
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            sw.Restart();
            collection.Shuffle();
            Console.WriteLine("Time : {0}", sw.ElapsedTicks);
            collection.PrintAllItemsOnConsole();
        }
        public void LinearSearchShouldWorkCorrectlyWithEmptyCollection()
        {
            var collection = new SortableCollection <int>();

            collection.Sort(new MergeSorter <int>());
            var found = collection.LinearSearch(21);

            Assert.IsFalse(found, "Element is found in empty collection!");
        }
        public void BinarySearchShouldWorkCorrectlyWhenSearchedElementIsFound()
        {
            var collection = new SortableCollection <int>(new int[] { 6, 1, 4, 2, 3, 21, -5, 8 });

            collection.Sort(new MergeSorter <int>());
            var found = collection.BinarySearch(21);

            Assert.IsTrue(found, "Element is not found in collection!");
        }
示例#30
0
        public void TestShouldFindValue()
        {
            var col = new SortableCollection <int>(new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 });

            col.Sort(new MergeSorter <int>());
            var searchvalue = 5;

            Assert.IsTrue(col.LinearSearch(searchvalue));
        }
示例#31
0
        public void ShouldSortCorrectlyOnlyNegativeValues()
        {
            var collection         = new SortableCollection <double>(new[] { -1.4, -8.6, -2, -13.1, -13.2, -55, -55, -55.1, -55.01 });
            var expectedCollection = new List <double>(collection.Items);

            expectedCollection.Sort();
            collection.Sort(new Quicksorter <double>());
            CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
        }
示例#32
0
        public void ShouldSortCorrectlyDoubles()
        {
            var collection         = new SortableCollection <double>(new[] { 1.4, -8.6, 2, 13.1, 13.2, 55, 55, 55.1, 55.01 });
            var expectedCollection = new List <double>(collection.Items);

            expectedCollection.Sort();
            collection.Sort(new Quicksorter <double>());
            CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
        }
示例#33
0
        public void ShouldSortCorrectlySortedCollection()
        {
            var collection         = new SortableCollection <int>(new[] { 1, 2, 3, 4, 5, 6, 7 });
            var expectedCollection = new List <int>(collection.Items);

            expectedCollection.Sort();
            collection.Sort(new Quicksorter <int>());
            CollectionAssert.AreEqual(expectedCollection, collection.Items.ToList());
        }
示例#34
0
        public void ExpectToFindValue()
        {
            var col = new SortableCollection <int>(new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 });

            col.Sort(new MergeSorter <int>());
            var searchvalue = -12;

            Assert.IsTrue(col.BinarySearch(searchvalue));
        }
        public void LinearSearchShouldWorkCorrectlyWhenSearchedElementIsNotFound()
        {
            var collection = new SortableCollection <int>(new int[] { 6, 1, 4, 2, 3, -5, 8 });

            collection.Sort(new MergeSorter <int>());
            var found = collection.LinearSearch(21);

            Assert.IsFalse(found, "Element is found in collection!");
        }
        public void TestLinearSearchResultIsRandom()
        {
            int[] input = { -1, 5, 8, 3, 4, 67, -9, 3, 9, 4 };
            SortableCollection <int> sortableCol = new SortableCollection <int>(input);

            sortableCol.Sort(new MergeSorter <int>());
            bool containsItem = sortableCol.LinearSearch(-9);

            Assert.IsTrue(containsItem);
        }
示例#37
0
        public void MyTestMethod()
        {
            var col = new SortableCollection <int>(new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 });

            col.Sort(new QuickSorter <int>());
            var expected = new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 };

            Array.Sort(expected);
            CollectionAssert.AreEqual(expected, col.Items.ToArray());
        }
        public void TestBinarySearchResultIsNotContained()
        {
            int[] input = { -1, 5, 8, 3, 4, 67, -9, 3, 9, 4 };
            SortableCollection <int> sortableCol = new SortableCollection <int>(input);

            sortableCol.Sort(new MergeSorter <int>());
            bool containsItem = sortableCol.BinarySearch(0);

            Assert.IsFalse(containsItem);
        }
        public void TestBinarySearchResultIsLast()
        {
            int[] input = { 8, 5, 8, 3, 4, 67, 9, 3, 9, -4 };
            SortableCollection <int> sortableCol = new SortableCollection <int>(input);

            sortableCol.Sort(new MergeSorter <int>());
            bool containsItem = sortableCol.BinarySearch(-4);

            Assert.IsTrue(containsItem);
        }
示例#40
0
        public void TestShouldSortCorrectly()
        {
            var col = new SortableCollection <int>(new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 });

            col.Sort(new MergeSorter <int>());
            var expected = new[] { -12, 3, 5 - 3, 1, 5, 6 - 2, -6, -22, 0, 123 };

            Array.Sort(expected);
            CollectionAssert.AreEqual(expected, col.Items.ToArray());
        }
        public void SortRandomCollectionTest()
        {
            SortableCollection<int> collection =
                new SortableCollection<int>(GenerateSorted(100));

            collection.Shuffle();
            collection.Sort(sorter);

            Assert.IsTrue(IsSorted(collection.Items));
        }
        public void BubbleSorter()
        {
            var collection = new SortableCollection<int>(new[] { 3, 3, 5, 1, 6, 4, 7, 10, 22, 0, 20, -5 });
            collection.Sort(new BubbleSorter<int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i] <= collection.Items[i + 1]);
            }
        }
        public void BubbleSorterTestReversed()
        {
            var collection = new SortableCollection<int>(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
            collection.Sort(new BubbleSorter<int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i] <= collection.Items[i + 1]);
            }
        }
示例#44
0
        public void TestSortWithTwoElements()
        {
            var collection = new SortableCollection <int>(1, -5);

            collection.Sort(TestSorter);

            CollectionAssert.AreEqual(
                new[] { -5, 1 },
                collection.ToArray(),
                "Sort method should sort the elements in ascending order.");
        }
示例#45
0
        public void TestSortWithOneElement()
        {
            var collection = new SortableCollection <int>(1);

            collection.Sort(TestSorter);

            CollectionAssert.AreEqual(
                new[] { 1 },
                collection.ToArray(),
                "Sorting collection with single element should have no effect.");
        }
示例#46
0
        public void TestSortWithNoElements()
        {
            var emptyCollection = new SortableCollection <int>();

            emptyCollection.Sort(TestSorter);

            CollectionAssert.AreEqual(
                new int[0],
                emptyCollection.ToArray(),
                "Sorting empty collection should have no effect.");
        }
示例#47
0
        public void MergeSortTest()
        {
            var collection = new SortableCollection <int>(new[] { 5, 1, 2, 4, 0, 6, 9, 8, 7 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i] < collection.Items[i + 1]);
            }
        }
示例#48
0
        public void SortedNumbersMergeSort()
        {
            var collection = new SortableCollection <int>(new[] { 1, 2, 3, 4, 5 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
示例#49
0
        public void SortCollection_OddItems()
        {
            var collection = new SortableCollection <int>(new int[] { 1, 10, 2, 9, 3, 8, 11, 4, 7, 6, 5 });

            collection.Sort(new SelectionSorter <int>());

            string expected = "1 2 3 4 5 6 7 8 9 10 11";
            string actual   = collection.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#50
0
        public void SortCollection_OneItem()
        {
            var collection = new SortableCollection <int>(new int[] { 1 });

            collection.Sort(new SelectionSorter <int>());

            string expected = "1";
            string actual   = collection.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#51
0
        public void SortEmptyCollection()
        {
            var collection = new SortableCollection <int>(new int[0]);

            collection.Sort(new SelectionSorter <int>());

            string expected = "";
            string actual   = collection.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void MethodShouldSortCorrectlyCollectionWithPossitiveNumbers()
        {
            var collection = new SortableCollection <int>(new[] { 52, 111, 33, 33, 46, 1125, 1 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
        public void MethodShouldSortCorrectlyCollectionWithEqualElements()
        {
            var collection = new SortableCollection <int>(new[] { 5, 5, 5, 5 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
        public void MethodShouldSortCorrectlyCollectionWithNegativeNumbers()
        {
            var collection = new SortableCollection <int>(new[] { -52, -111, -33, -33, -46, -1125, -1 });

            collection.Sort(new SelectionSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
示例#55
0
        public void ReversedNumbersSelectionSort()
        {
            var collection = new SortableCollection <int>(new[] { 9, 7, 5, 3 });

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

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
示例#56
0
        public void NegativeNumbersMergeSort()
        {
            var collection = new SortableCollection <int>(new[] { -5, -16, -1, -29 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
示例#57
0
        public void BinarySearchEmptyTest()
        {
            List <int> testCollection = new List <int>();
            SortableCollection <int> testSortableColleciton = new SortableCollection <int>(testCollection);

            testSortableColleciton.Sort(new QuickSorter <int>());

            bool searchResult = testSortableColleciton.BinarySearch(1);

            Assert.IsFalse(searchResult);
        }
        public void MethodShouldSortCorrectlyCollection()
        {
            var collection = new SortableCollection <int>(new[] { 52, -111, -33, 33, -46, 0, -1 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i].CompareTo(collection.Items[i + 1]) <= 0);
            }
        }
示例#59
0
        public void MergeSortReverseSortedTest()
        {
            var collection = new SortableCollection <int>(new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });

            collection.Sort(new MergeSorter <int>());

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                Assert.IsTrue(collection.Items[i] < collection.Items[i + 1]);
            }
        }
        public void TestSortWithDuplicatedValues()
        {
            var collection = new SortableCollection <int>(new[] { 14, 1, 10, 3, -4, 10, 5, 3 });
            var expected   = new SortableCollection <int>(new[] { -4, 1, 3, 3, 5, 10, 10, 14 });

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

            for (int i = 0; i < collection.Items.Count; i++)
            {
                Assert.AreEqual(expected.Items[i], collection.Items[i]);
            }
        }