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

                // Assert
                Assert.Equal(expected, actual);
            }
Exemplo n.º 2
0
            public void UInt32_ShouldReturnExpectedResul(uint value, uint lowerBound, uint upperBound, uint expected)
            {
                // Act
                var actual = IntegerMath.Clamp(value, lowerBound, upperBound);

                // Assert
                Assert.Equal(expected, actual);
            }
Exemplo n.º 3
0
            public void Int64_ShouldReturnExpectedResul(long value, long lowerBound, long upperBound, long expected)
            {
                // Act
                var actual = IntegerMath.Clamp(value, lowerBound, upperBound);

                // 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);
            }
Exemplo n.º 5
0
            public void UInt32_ShouldThrowArgumentOutOfRangeException_WhenLowerBoundIsGreaterThanUpperBound()
            {
                // Act
                var exception = Record.Exception(() =>
                {
                    IntegerMath.Clamp((uint)20, (uint)20, (uint)0);
                });

                // Assert
                Assert.IsType <ArgumentOutOfRangeException>(exception);
            }
Exemplo n.º 6
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));
            }
        }