Esempio n. 1
0
        public void TestBubbleSort_EmptyJaggedArrayFirstItemDesc_ArgumentException()
        {
            var jaggedArray = new int[0][];

            int parameter(int[] arr) => arr[0];

            Assert.Throws <ArgumentException>(() => BubbleAlgorithm.BubbleSort(jaggedArray, parameter));
        }
Esempio n. 2
0
        public static long BubbleTime(float[] array, TimeType type) => BubbleAlgorithm.Time(array, type); //returns time

        /// <summary>
        /// Returns prepared message of duration in ticks.
        /// </summary>
        /// <param name="array">Float array to sort.</param>
        /// <param name="type">Type of returned duration.</param>
        public static string BubbleTimePrint(float[] array, TimeType type)
        {
            if (type == TimeType.Both)
            {
                return(string.Format("Bubble Sorting Duration: {0} Miliseconds / {1} Ticks.", BubbleAlgorithm.Time(array, TimeType.Miliseconds), BubbleAlgorithm.Time(array, TimeType.Ticks))); //returns preprepared messageof time
            }
            return(string.Format("Bubble Sorting Duration: {0} {1}", BubbleAlgorithm.Time(array, type), type == TimeType.Ticks ? "Ticks." : "Miliseconds."));                                   //returns preprepared message of time
        }
Esempio n. 3
0
        public void TestBubbleSort_JaggedArrayByNull_ArgumentNullException()
        {
            var jaggedArray = new int[][]
            {
                new int[] { 1 },
                new int[] { 2, 5, 2, 2, 1 },
                new int[] { 3, 1, 2 },
                new int[] { 4, 1, 4, 3 }
            };

            Assert.Throws <ArgumentNullException>(() => BubbleAlgorithm.BubbleSort(jaggedArray, null));
        }
Esempio n. 4
0
        public void TestBubbleSort_JaggedArrayWithNullByFirstItemDesc_ArgumentNullException()
        {
            var jaggedArray = new int[][]
            {
                new int[] { 1 },
                new int[] { 2, 5, 2, 2, 1 },
                null,
                new int[] { 4, 1, 4, 3 }
            };

            int parameter(int[] arr) => arr[0];

            Assert.Throws <ArgumentNullException>(() => BubbleAlgorithm.BubbleSort(jaggedArray, parameter));
        }
Esempio n. 5
0
        public void BubbleTest()
        {
            Initialize();
            var bubble = new BubbleAlgorithm(Items.ToArray());

            bubble.Sort(cancellationTokenSource.Token);

            var collection = bubble.GetCollection();

            for (int i = 0; i < bubble.CollectionSize; i++)
            {
                Assert.AreEqual(Sorted[i], collection[i]);
            }
        }
Esempio n. 6
0
        public void TestBubbleSortByMax_JaggedArray_SortedArray()
        {
            var jaggedArray = new int[][]
            {
                new int[] { 1, 2, 3, 4, 5, 6, 7 },
                new int[] { 1, 2, 3, 4 },
                new int[] { 1, 2, 3, 4, 5 },
                new int[] { 1, 2 }
            };
            var expected = new int[][]
            {
                new int[] { 1, 2 },
                new int[] { 1, 2, 3, 4 },
                new int[] { 1, 2, 3, 4, 5 },
                new int[] { 1, 2, 3, 4, 5, 6, 7 }
            };

            BubbleAlgorithm.BubbleSortByMax(jaggedArray);

            Assert.AreEqual(expected, jaggedArray);
        }
Esempio n. 7
0
        public void TestBubbleSortByMin_JaggedArrayDesc_SortedArray()
        {
            var jaggedArray = new int[][]
            {
                new int[] { 4, 5, 6, 7 },
                new int[] { 2, 3, 4 },
                new int[] { 3, 4, 5 },
                new int[] { 1, 2 }
            };
            var expected = new int[][]
            {
                new int[] { 4, 5, 6, 7 },
                new int[] { 3, 4, 5 },
                new int[] { 2, 3, 4 },
                new int[] { 1, 2 }
            };

            BubbleAlgorithm.BubbleSortByMin(jaggedArray, true);

            Assert.AreEqual(expected, jaggedArray);
        }
Esempio n. 8
0
        public void TestBubbleSort_JaggedArrayByFirstItemDesc_SortedArray()
        {
            var jaggedArray = new int[][]
            {
                new int[] { 1 },
                new int[] { 2, 5, 2, 2, 1 },
                new int[] { 3, 1, 2 },
                new int[] { 4, 1, 4, 3 }
            };
            var expected = new int[][]
            {
                new int[] { 4, 1, 4, 3 },
                new int[] { 3, 1, 2 },
                new int[] { 2, 5, 2, 2, 1 },
                new int[] { 1 },
            };

            int parameter(int[] arr) => arr[0];

            BubbleAlgorithm.BubbleSort(jaggedArray, parameter, true);

            Assert.AreEqual(expected, jaggedArray);
        }
Esempio n. 9
0
 public BubbleSeries(object configuration)
 {
     Model         = new BubbleAlgorithm(this);
     Configuration = configuration;
     InitializeDefuaults();
 }
Esempio n. 10
0
 public BubbleSeries()
 {
     Model = new BubbleAlgorithm(this);
     InitializeDefuaults();
 }
Esempio n. 11
0
 public void TestBubbleSort_NullByNull_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => BubbleAlgorithm.BubbleSort(null, null));
 }
Esempio n. 12
0
        public void TestBubbleSort_NullByFirstItemDesc_ArgumentNullException()
        {
            int parameter(int[] arr) => arr[0];

            Assert.Throws <ArgumentNullException>(() => BubbleAlgorithm.BubbleSort(null, parameter));
        }
Esempio n. 13
0
 /// <summary>
 /// Returns duration of algorithm calculations in ticks.
 /// </summary>
 /// <param name="array">Flaot array to sort.</param>
 /// <param name="type">Type of returned duration.</param>
 public static long BubbleTime(float[] array, TimeType type) => BubbleAlgorithm.Time(array, type); //returns time
Esempio n. 14
0
 /// <summary>
 /// Sorting an double array with using bubble algorithm.
 /// </summary>
 /// <param name="array">Double array to sort.</param>
 public static void Bubble(double[] array) => BubbleAlgorithm.Sort(array);
Esempio n. 15
0
 /// <summary>
 /// Sorting an float array with using bubble algorithm.
 /// </summary>
 /// <param name="array">Float array to sort.</param>
 public static void Bubble(float[] array) => BubbleAlgorithm.Sort(array);