Exemplo n.º 1
0
        private static void MatrixCycle(int rowFromInclusive, int rowToInclusive, int columnFromInclusive, int columnToInclusive, int yStride, int xStride, int maxDegreeOfParallelism, InnerCycle innerCycle, CancellationToken cancellationToken = default)
        {
            OutOfRangeException.Check(nameof(maxDegreeOfParallelism), maxDegreeOfParallelism, 0);

            var iRows = new List <int>();

            for (var iRow = rowFromInclusive; iRow <= rowToInclusive; iRow += yStride)
            {
                iRows.Add(iRow);
            }

            if (maxDegreeOfParallelism > 1)
            {
                Parallel.ForEach(iRows,
                                 new ParallelOptions
                {
                    MaxDegreeOfParallelism = maxDegreeOfParallelism,
                    CancellationToken      = cancellationToken
                },
                                 iRow =>
                {
                    var row = (iRow - rowFromInclusive) / yStride;
                    ColumnCycle(columnFromInclusive, columnToInclusive, iRow, row, xStride, innerCycle);
                });
            }
            else
            {
                var row = 0;
                foreach (var iRow in iRows)
                {
                    ColumnCycle(columnFromInclusive, columnToInclusive, iRow, row, xStride, innerCycle);
                    row++;
                }
            }
Exemplo n.º 2
0
        protected static void AssertOutOfRangeException <T>(OutOfRangeException <T> exception, string paramName, T actualValue, T min, T max)
        {
            Assert.NotNull(exception);

            var expectedMessage = new OutOfRangeException <T>(actualValue, min, max, paramName).Message;

            Assert.Equal(expectedMessage, exception.Message);
        }
Exemplo n.º 3
0
        private static bool TestForException(string CheckInput, int Start, int End)
        {
            bool Result = true;

            try
            {
                int Number = int.Parse(CheckInput);

                if (Number < Start || Number > End) // checking if the number is out of range
                {
                    var ex = new OutOfRangeException();
                    throw ex;
                }

                return(Result);
            }
            catch (OutOfRangeException) // our own exception is needed
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Number - out of given range!");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Please, try again: ");
                Console.ForegroundColor = ConsoleColor.White;
                Result = false;
                return(Result);
            }
            catch (NullReferenceException)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Number - value cannot be null!");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Please, try again: ");
                Console.ForegroundColor = ConsoleColor.White;
                Result = false;
                return(Result);
            }
            catch (FormatException)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Number - input is not a number!");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Please, try again: ");
                Console.ForegroundColor = ConsoleColor.White;
                Result = false;
                return(Result);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Create rectangle from center coordinates and height / width
        /// </summary>
        /// <param name="y">center row</param>
        /// <param name="x">center column</param>
        /// <param name="rows">total height</param>
        /// <param name="columns">total width</param>
        /// <returns>a new rectangle</returns>
        public static Rectangle FromCenter(int y, int x, int rows, int columns)
        {
            EvenException.Check(nameof(rows), rows);
            EvenException.Check(nameof(columns), columns);

            OutOfRangeException.Check(nameof(rows), rows, 1);
            OutOfRangeException.Check(nameof(columns), columns, 1);

            var relHeight = (rows - 1) / 2;
            var relWidth  = (columns - 1) / 2;

            var top  = y - relHeight;
            var left = x - relWidth;

            var region = new Rectangle(left, top, columns, rows);

            return(region);
        }
Exemplo n.º 5
0
 public void OutOfRange()
 {
     OutOfRangeException.Check("", 1, 0, 10);
     Assert.Pass();
 }
Exemplo n.º 6
0
 public void OutOfRange_Exception_ToBig1()
 {
     Assert.Catch <OutOfRangeException>(() => OutOfRangeException.Check("", 11, max: 10));
 }
Exemplo n.º 7
0
 public void OutOfRange_Exception_ToSmall1()
 {
     Assert.Catch <OutOfRangeException>(() => OutOfRangeException.Check("", 1, 5));
 }