Exemplo n.º 1
0
        public void BubbleSortTestDecreasingOrder10toThePowerOf4()
        {
            SetupStageDecreasingOrder10toThePowerOf4();
            List <int> original = new List <int>(ints.ToArray());

            Sorter.BubbleSort(ints);
            GeneralAssertions(original);
        }
Exemplo n.º 2
0
        public void BubbleSortTestAleatoryOrder10toThePowerOf3()
        {
            SetupStageAleatoryOrder10toThePowerOf3();
            List <int> original = new List <int>(ints.ToArray());

            Sorter.BubbleSort(ints);
            GeneralAssertions(original);
        }
Exemplo n.º 3
0
        public void BubbleSortOnDescendingArrayOf100()
        {
            int[] arr = CloneDesc;
            Sorter <int> .BubbleSort(arr);

            string actual = ArrayToString(arr);

            Assert.AreEqual(expected, actual);
        }
    static void Main()
    {
        var values = new int[] { 5, 4, 3, 2, 1 };

        Sorter.Print("Not sorted: ", values);
        Sorter.BubbleSort(values);
        Sorter.Print("Sorted: ", values);

        Console.ReadLine();
    }
        public void CheckThatBubbleSortCanSortNumbers(string toSort, string expected)
        {
            Sorter sorter = new Sorter();

            IList <int> actualResult = sorter.BubbleSort <int>(toSort.Split(',').Select(int.Parse).ToArray());

            IEnumerable <int> expectedResult = expected.Split(',').Select(int.Parse);

            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 6
0
        public void Sorter_Null_ReturnsNull()
        {
            // Arrange

            // Act
            var sut    = new Sorter();
            var result = sut.BubbleSort(null);

            // Assert
            Assert.IsNull(result);
        }
Exemplo n.º 7
0
        public void Bubble_Sort_Test(int[] input, int[] expectedResult)
        {
            // arrange
            Sorter sorter = new Sorter();

            // act
            IList <int> actualResult = sorter.BubbleSort(input.ToList());

            // assert
            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 8
0
        public void Sorter_EmptyArray_ReturnsEmptyArray()
        {
            // Arrange
            var numbers = new int[0];

            // Act
            var sut    = new Sorter();
            var result = sut.BubbleSort(numbers);

            // Assert
            Assert.AreEqual(0, result.Length);
        }
Exemplo n.º 9
0
        public void Sorter_SingleElement_ReturnsSingleElement()
        {
            // Arrange
            var numbers = new[] { 5 };

            // Act
            var sut    = new Sorter();
            var result = sut.BubbleSort(numbers);

            // Assert
            Assert.AreEqual(5, result[0]);
            Assert.AreEqual(1, result.Length);
        }
Exemplo n.º 10
0
        public void Sorter_Unsorted_ReturnsSorted()
        {
            // Arrange
            var numbers = new[] { 5, 4, 7, 3, 8, 2, 1 };

            // Act
            var sut    = new Sorter();
            var result = sut.BubbleSort(numbers);

            // Assert
            var expected = new[] { 1, 2, 3, 4, 5, 7, 8 };

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }

            Assert.AreEqual(expected.Length, result.Length);
        }
Exemplo n.º 11
0
        public void BubbleSort()
        {
            int[] lst = new int[50];
            int[] cpy = new int[50];

            Sorter <int> s = new Sorter <int>();
            Random       r = new Random();

            for (int i = 0; i < 50; i++)
            {
                lst[i] = r.Next(1000);
            }

            Array.Copy(lst, cpy, 50);
            Array.Sort(cpy);

            s.BubbleSort(lst);

            for (int i = 0; i < 50; i++)
            {
                Assert.AreEqual <int>(cpy[i], lst[i], "elements do not match");
            }
        }
        /**
         * Main method which initialize the program as a Main object<br>
         * @param args made for the main method
         */
        public static void Main(string[] args)
        {
            //Method to export CSV file
            StreamWriter sw = new StreamWriter(PATH);

            sw.WriteLine("#HEADERS SPECIFICATIONS");
            sw.WriteLine("#first character: \"b\" is for BubbleSort and \"i\" is for InsertionSort");
            sw.WriteLine("#second characer: \"a\" is for aleatory order, \"i\" is for increasing order and \"d\" is for decreasing order");
            sw.WriteLine("#third character: \"1\", \"2\", \"3\" and \"4\" refer to the input size (10 ^ third character)");
            sw.WriteLine("ba1,ia1,bi1,ii1,bd1,id1,ba2,ia2,bi2,ii2,bd2,id2,ba3,ia3,bi3,ii3,bd3,id3,ba4,ia4,bi4,ii4,bd4,id4");

            for (int i = 0; i < 1000; i++)
            {
                String repetition = "";

                SetupStageAleatoryOrder10toThePowerOf1();
                long t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                long t2       = CurrentTimeMillis();
                long duration = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf1();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf1();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf1();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf1();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf1();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf2();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf3();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAleatoryOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageAscendingOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.BubbleSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration + ",";

                SetupStageDecreasingOrder10toThePowerOf4();
                t1 = CurrentTimeMillis();
                Sorter.InsertionSort(ints);
                t2          = CurrentTimeMillis();
                duration    = t2 - t1;
                repetition += duration;

                sw.WriteLine(repetition);
            }
            sw.Close();
        }
Exemplo n.º 13
0
 /// <summary>
 /// this is only for test
 /// </summary>
 public void SortProbabilities()
 {
     probabilities = Sorter.BubbleSort(probabilities);
 }
        public void CheckThatBubbleSortCanSortString(string toSort, string expected)
        {
            IList <string> actualResult = _sorter.BubbleSort(toSort.Split(','));

            Assert.AreEqual(expected.Split(','), actualResult);
        }