Exemplo n.º 1
0
        public void SortCharArrayWithGenericApproach()
        {
            var bubbleSort            = new GenericBubbleSort();
            var charArray             = new char[] { 'a', 'f', 'z', 'a', 'b', 'u', 'w' };
            var ascendingSortedArray  = bubbleSort.Sort <char>(charArray, new IntOrCharComparer(), Order.Ascending);
            var descendingSortedArray = bubbleSort.Sort <char>(charArray, new IntOrCharComparer(), Order.Descending);

            Assert.Equal(new char[] { 'a', 'a', 'b', 'f', 'u', 'w', 'z' }, ascendingSortedArray);
            Assert.Equal(new char[] { 'z', 'w', 'u', 'f', 'b', 'a', 'a' }, descendingSortedArray);
        }
Exemplo n.º 2
0
        public void SortIntArrayWithGenericApproach()
        {
            var bubbleSort            = new GenericBubbleSort();
            var intArray              = new int[] { 2, 1, 1, 10, 25, 43 };
            var ascendingSortedArray  = bubbleSort.Sort <int>(intArray, new IntOrCharComparer(), Order.Ascending);
            var descendingSortedArray = bubbleSort.Sort <int>(intArray, new IntOrCharComparer(), Order.Descending);

            Assert.Equal(new int[] { 1, 1, 2, 10, 25, 43 }, ascendingSortedArray);
            Assert.Equal(new int[] { 43, 25, 10, 2, 1, 1 }, descendingSortedArray);
        }