Exemple #1
0
 public bool IsBetween_BoundsType(uint value, uint min, uint max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, boundsType));
 }
 public bool IsBetweenEither_BoundsType(ulong value, ulong min, ulong max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetweenEither(min, max, boundsType));
 }
Exemple #3
0
 public bool IsBetweenEither_BoundsType(decimal value, decimal min, decimal max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetweenEither(min, max, boundsType));
 }
Exemple #4
0
 public bool IsBetween(decimal value, decimal min, decimal max, bool allowEitherOrder, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, allowEitherOrder, boundsType));
 }
        /// <summary>
        /// Ensures the expression and corresponding value evaluates to between the specified values
        /// </summary>
        /// <param name="exp">The exp.</param>
        /// <param name="val">The value.</param>
        /// <param name="bound1">The bound1.</param>
        /// <param name="bound2">The bound2.</param>
        /// <param name="allowEitherOrder">if set to <c>true</c> [allow either order].</param>
        /// <param name="boundsType">Type of the bounds.</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        public static void IsBetween(Expression <Func <byte> > exp, byte val, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType)
        {
            if (val.IsBetween(bound1, bound2, allowEitherOrder, boundsType))
            {
                return;
            }

            var memberName = ExpressionExtensions.GetMemberName(exp);

            throw new ArgumentOutOfRangeException(
                      memberName,
                      val,
                      string.Format("{0} must be {1}",
                                    memberName,
                                    string.Format(boundsType.GetLimitDescriptionFormat(),
                                                  MathsByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder),
                                                  MathsByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder)
                                                  )
                                    )
                      );
        }
 public string GetLimitDescriptionFormatTest(IsBetweenBoundsType boundsType)
 {
     return(boundsType.GetLimitDescriptionFormat());
 }
 /// <summary>
 /// Ensures the expression and corresponding value evaluates to between the specified values
 /// </summary>
 /// <param name="exp">The exp.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <param name="boundsType">Type of the bounds.</param>
 public static void IsBetween(Expression <Func <byte> > exp, byte min, byte max, IsBetweenBoundsType boundsType)
 {
     IsBetween(exp, min, max, false, boundsType);
 }
Exemple #8
0
 /// <summary>
 /// Determines whether the specified value is between min and max.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <param name="boundsType">Control boundary checking.</param>
 /// <returns><c>true</c> if the specified minimum is between; otherwise, <c>false</c>.</returns>
 public static bool IsBetween(this uint value, uint min, uint max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, false, boundsType));
 }
 public bool IsBetweenEither_BoundsType(sbyte value, sbyte min, sbyte max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetweenEither(min, max, boundsType));
 }
 public bool IsBetween(sbyte value, sbyte min, sbyte max, bool allowEitherOrder, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, allowEitherOrder, boundsType));
 }
 public bool IsBetweenEither_BoundsType(ushort value, ushort min, ushort max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetweenEither(min, max, boundsType));
 }
        /// <summary>
        /// Determines whether the specified value is between min and max with full control over bounds checking.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <param name="allowEitherOrder">if set to <c>true</c> allow min/max in either order.</param>
        /// <param name="boundsType">Control boundary checking.</param>
        /// <returns><c>true</c> if the specified minimum is between min and max; otherwise, <c>false</c>.</returns>
        public static bool IsBetween(this float value, float min, float max, bool allowEitherOrder, IsBetweenBoundsType boundsType)
        {
            var lowerBound = GetLowerBound(min, max, allowEitherOrder);
            var upperBound = GetUpperBound(min, max, allowEitherOrder);

            switch (boundsType)
            {
            case IsBetweenBoundsType.IncludeLowerAndUpper:
                return((value >= lowerBound) && (value <= upperBound));

            case IsBetweenBoundsType.ExcludeLowerAndUpper:
                return((value > lowerBound) && (value < upperBound));

            case IsBetweenBoundsType.IncludeLowerExcludeUpper:
                return((value >= lowerBound) && (value < upperBound));

            case IsBetweenBoundsType.ExcludeLowerIncludeUpper:
                return((value > lowerBound) && (value <= upperBound));

            default:
                return(false);
            }
        }
 /// <summary>
 /// Determines whether the specified value is between the smaller of min and max and the larger of min and max.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <param name="boundsType">Control boundary checking.</param>
 /// <returns><c>true</c> if [is between either] [the specified minimum]; otherwise, <c>false</c>.</returns>
 public static bool IsBetweenEither(this float value, float min, float max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, true, boundsType));
 }
 public bool IsBetween(ulong value, ulong min, ulong max, bool allowEitherOrder, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, allowEitherOrder, boundsType));
 }
 /// <summary>
 /// Ensures the expression evaluates to between the specified values
 /// </summary>
 /// <param name="exp">The exp.</param>
 /// <param name="bound1">The bound1.</param>
 /// <param name="bound2">The bound2.</param>
 /// <param name="allowEitherOrder">if set to <c>true</c> [allow either order].</param>
 /// <param name="boundsType">Type of the bounds.</param>
 public static void IsBetween(Expression <Func <byte> > exp, byte bound1, byte bound2, bool allowEitherOrder, IsBetweenBoundsType boundsType)
 {
     IsBetween(exp, exp.Compile().Invoke(), bound1, bound2, allowEitherOrder, boundsType);
 }
        public bool Guard_IsBetween(decimal value, decimal min, decimal max, bool allowEitherOrder, IsBetweenBoundsType boundsType, string messageText)
        {
            try
            {
                // Act
                Guard.IsBetween(() => value, min, max, allowEitherOrder, boundsType);

                return(true);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.IsNotNull(messageText);
                Assert.IsNotEmpty(messageText);
                ex.Message.ShouldStartWith(messageText);
                return(false);
            }
            catch (Exception ex)
            {
                // Assert
                Assert.Fail(ex.Message);
                return(false);
            }
        }
 /// <summary>
 /// Determines whether the specified value is between the smaller of min and max and the larger of min and max.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <param name="boundsType">Control boundary checking.</param>
 /// <returns><c>true</c> if [is between either] [the specified minimum]; otherwise, <c>false</c>.</returns>
 public static bool IsBetweenEither(this ulong value, ulong min, ulong max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, true, boundsType));
 }