コード例 #1
0
        private void AssertMaxSliceForArrayIs(int[] input, ArraySum expected)
        {
            var sut    = CreateSut();
            var actual = sut.FindMaximumSlice(input);

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void ParallelSimdForHasToBeEqual()
        {
            var a = GenerateRandomArrayWithLength(Size);
            var b = GenerateRandomArrayWithLength(Size);

            var forLoopOut          = ArraySum.ForLoop(a, b);
            var forLoopParallelSimd = ArraySum.ParallelSimdFor(a, b);

            AreEqual(forLoopOut, forLoopParallelSimd);
        }
コード例 #3
0
        public void ParallelPartitionedHasToBeEqual()
        {
            var a = GenerateRandomArrayWithLength(Size);
            var b = GenerateRandomArrayWithLength(Size);

            var forLoopOut = ArraySum.ForLoop(a, b);
            var forLoopParallelPartioned = ArraySum.ParallelForPartioned(a, b);

            AreEqual(forLoopOut, forLoopParallelPartioned);
        }
コード例 #4
0
        public void ConstForHasToBeEqual()
        {
            var a = GenerateRandomArrayWithLength(Size);
            var b = GenerateRandomArrayWithLength(Size);

            var forLoopOut   = ArraySum.ForLoop(a, b);
            var forLoopConst = ArraySum.ForLoopConst(a, b);

            AreEqual(forLoopOut, forLoopConst);
        }
コード例 #5
0
        public void ReverseForHasToBeEqual()
        {
            var a = GenerateRandomArrayWithLength(Size);
            var b = GenerateRandomArrayWithLength(Size);

            var forLoopOut        = ArraySum.ForLoop(a, b);
            var forLoopReverseOut = ArraySum.ForLoopReverse(a, b);

            AreEqual(forLoopOut, forLoopReverseOut);
        }
コード例 #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ArraySumTest()
 {
     _algorithm = new ArraySum();
 }
コード例 #7
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Button    clickedButton = (Button)sender;
            Stopwatch sw            = new Stopwatch();

            switch (clickedButton.Name.ToLower())
            {
            case "quick":
                break;

            case "insertion":
                iStatus.Text         = RUNNING;
                iSortRuntime.Content = string.Empty;
                sw.Start();
                await InsertionSort.SortAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                iStatus.Text         = COMPLETE;
                iSortRuntime.Content = sw.Elapsed;
                break;

            case "evenodd":
                eoStatus.Text         = RUNNING;
                eoSortRuntime.Content = string.Empty;
                sw.Start();
                await EvenOddSort.SortAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                eoStatus.Text         = COMPLETE;
                eoSortRuntime.Content = sw.Elapsed;
                break;

            case "arrayadd":
                arrayAddStatus.Text     = RUNNING;
                arrayAddRuntime.Content = string.Empty;
                sw.Start();
                await ArrayAddition.AddArraysAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100),
                                                   RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                arrayAddStatus.Text     = COMPLETE;
                arrayAddRuntime.Content = sw.Elapsed;
                break;

            case "arraysum":
                arraySumStatus.Text     = RUNNING;
                arraySumRuntime.Content = string.Empty;
                sw.Start();
                await ArraySum.SumAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                arraySumStatus.Text     = COMPLETE;
                arraySumRuntime.Content = sw.Elapsed;
                break;

            case "parrayadd":
                pArrayAddStatus.Text     = RUNNING;
                pArrayAddRuntime.Content = string.Empty;
                sw.Start();
                await ParallelArrayAddition.AddArraysAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100),
                                                           RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                pArrayAddStatus.Text     = COMPLETE;
                pArrayAddRuntime.Content = sw.Elapsed;
                break;

            case "psum":
                pSumStatus.Text     = RUNNING;
                pSumRuntime.Content = string.Empty;
                sw.Start();
                await ParallelSum.SumAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);

                sw.Stop();
                pSumStatus.Text     = COMPLETE;
                pSumRuntime.Content = sw.Elapsed;
                break;

            case "reduct":
                reductStatus.Text     = RUNNING;
                reductRuntime.Content = string.Empty;
                sw.Start();
                await ReductionSum.SumAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100));

                sw.Stop();
                reductStatus.Text     = COMPLETE;
                reductRuntime.Content = sw.Elapsed;
                break;

            case "all":
                iSortRuntime.Content     = string.Empty;
                eoSortRuntime.Content    = string.Empty;
                arrayAddRuntime.Content  = string.Empty;
                arraySumRuntime.Content  = string.Empty;
                pArrayAddRuntime.Content = string.Empty;
                pSumRuntime.Content      = string.Empty;
                allRuntime.Content       = string.Empty;
                iStatus.Text             = RUNNING;
                eoStatus.Text            = RUNNING;
                arrayAddStatus.Text      = RUNNING;
                arraySumStatus.Text      = RUNNING;
                pArrayAddStatus.Text     = RUNNING;
                pSumStatus.Text          = RUNNING;
                allStatus.Text           = RUNNING;
                sw.Start();
                Task inSort = InsertionSort.SortAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                Task eoSort = EvenOddSort.SortAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                Task arrAdd = ArrayAddition.AddArraysAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100),
                                                           RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                Task arrSum = ArraySum.SumAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                Task parAdd = ParallelArrayAddition.AddArraysAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100),
                                                                   RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                Task parSum = ParallelSum.SumAsync(RandomArray.GetRandomArray(DatasetSize, 0, 100), _cts);
                await inSort.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        iStatus.Text = COMPLETE;
                    });
                });

                await eoSort.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        eoStatus.Text = COMPLETE;
                    });
                });

                await arrAdd.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        arrayAddStatus.Text = COMPLETE;
                    });
                });

                await arrSum.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        arraySumStatus.Text = COMPLETE;
                    });
                });

                await parAdd.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        pArrayAddStatus.Text = COMPLETE;
                    });
                });

                await parSum.ContinueWith(t =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        pSumStatus.Text = COMPLETE;
                    });
                });

                await Task.WhenAll(inSort, eoSort);

                sw.Stop();
                allRuntime.Content = sw.Elapsed;
                allStatus.Text     = COMPLETE;
                break;

            case "cancel":
                _cts?.Cancel();
                _cts = new CancellationTokenSource();
                break;

            default:
                break;
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            int[] array = { 3, 2, 1, 4 };
            int[,] arrayTwo = { { 1, 2, 3, -3, -6 }, { 3, 2, 1, -4, -20 } };

            Rectangle rectangle = new Rectangle(3, 4);

            try
            {
                BubbleSort.SortAsc(array);
                Console.WriteLine("Array sorted in ASC: ");
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            foreach (int s in array)
            {
                Console.WriteLine(s);
            }
            try
            {
                BubbleSort.SortDesc(array);
                Console.WriteLine("Array sorted in DESC: ");
            }

            catch (NullReferenceException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            foreach (int s in array)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("The sum of positive numbers of a two-dimensional array: ");

            try
            {
                int sumPositive = ArraySum.CalcSumPositive(arrayTwo);
                Console.WriteLine(sumPositive);
            }

            catch (NullReferenceException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            try
            {
                int perimetr = rectangle.CalcPerimeter(rectangle.Width, rectangle.Height);
                Console.WriteLine("Rectangle perimeter: " + perimetr);
            }

            catch (NegativeException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            try
            {
                int square = rectangle.CalcSquare(rectangle.Width, rectangle.Height);
                Console.WriteLine("Rectangle square: " + square);
            }

            catch (NegativeException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            Console.ReadLine();
        }
コード例 #9
0
        public void TestArraySumAccuracy()
        {
            int[] inputArray = { 1, 2, 3, 4, 5 };

            Assert.AreEqual(15, ArraySum.Sum(inputArray));
        }
コード例 #10
0
 public ArraySumTest()
 {
     arraySum = new ArraySum();
 }