public void Int32_ShouldReturnExpectedResult(int dividend, int divisor, int expected)
            {
                // Act
                var actual = IntegerMath.Modulo(dividend, divisor);

                // Assert
                Assert.Equal(expected, actual);
            }
            public void Int32_ShouldThrowDivideByZeroException_WhenDivisorIsZero()
            {
                // Act
                var exception = Record.Exception(() =>
                {
                    IntegerMath.Modulo((int)10, (int)0);
                });

                // Assert
                Assert.IsType <DivideByZeroException>(exception);
            }
示例#3
0
        /// <summary>
        /// Calculates the padding needed to get the specified offset to a multiple of the specified boundary.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <param name="boundary">The boundary.</param>
        /// <returns>The number of padding bytes to add.</returns>
        public static long GetPadding(long offset, int boundary)
        {
            #region Contract
            if (boundary <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(boundary));
            }
            #endregion

            if (BinaryMath.IsPowerOfTwoOrZero(boundary))
            {
                return((long)BinaryMath.GetPadding(unchecked ((ulong)offset), boundary));
            }
            else
            {
                return(IntegerMath.Modulo(boundary - IntegerMath.Modulo(offset, boundary), boundary));
            }
        }