コード例 #1
0
ファイル: IsBetweenTests.cs プロジェクト: wtfcolt/game
        public void IsBetweenSByteTest()
        {
            for (sbyte i = -20; i < 20; i++)
            {
                for (sbyte j = -20; j < 20; j++)
                {
                    for (sbyte k = -30; k < 30; k++)
                    {
                        var b = k.IsBetween(i, j);

                        bool b2;
                        if (i < j)
                        {
                            b2 = (k >= i && k <= j);
                        }
                        else
                        {
                            b2 = (k >= j && k <= i);
                        }

                        Assert.AreEqual(b, b2);
                    }
                }
            }
        }
コード例 #2
0
        /// <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 <sbyte> > exp, sbyte val, sbyte bound1, sbyte 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(),
                                                  MathsSByteExtensions.GetLowerBound(bound1, bound2, allowEitherOrder),
                                                  MathsSByteExtensions.GetUpperBound(bound1, bound2, allowEitherOrder)
                                                  )
                                    )
                      );
        }
コード例 #3
0
 public static bool IsInRange(this sbyte value, sbyte min, sbyte max, Clusivity clusivity       = Clusivity.Inclusive) => value.IsBetween(min, max, clusivity);
コード例 #4
0
 /// <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 sbyte value, sbyte min, sbyte max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, true, boundsType));
 }
コード例 #5
0
 /// <summary>
 /// Determines whether the specified value is inclusively between min and max.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <returns><c>true</c> if the specified minimum is between min and max; otherwise, <c>false</c>.</returns>
 public static bool IsBetween(this sbyte value, sbyte min, sbyte max)
 {
     return(value.IsBetween(min, max, IsBetweenBoundsType.Inclusive));
 }
 public bool IsBetween(sbyte value, sbyte min, sbyte max, bool allowEitherOrder, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, allowEitherOrder, boundsType));
 }
 public bool IsBetween_BoundsType(sbyte value, sbyte min, sbyte max, IsBetweenBoundsType boundsType)
 {
     return(value.IsBetween(min, max, boundsType));
 }
 public bool IsBetween_Default(sbyte value, sbyte min, sbyte max)
 {
     return(value.IsBetween(min, max));
 }