void LessThanOrEquals(IComparable x, Object y, Boolean expected) { Boolean result = default; Test.IfNot.Action.ThrowsException(() => result = x.IsLessThanOrEqual(y), out Exception ex); Test.If.Value.IsEqual(result, expected); }
/// <summary> /// Checks if a value is clamped in a given inclusive range. /// </summary> /// <param name="_this">The <see cref="IComparable"/> that is checked against the range.</param> /// <param name="min">The lower border of the range. Is considered lower than <paramref name="_this"/> if null.</param> /// <param name="max">The upper border of the range. Is considered higher than <paramref name="_this"/> if null.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="_this"/> is null.</exception> /// <returns>True if <paramref name="_this"/> is clamped, false if not.</returns> /// <example> /// <code> /// if(someIndex.IsClamped(0, someList.Count - 1)) { /// doSomething(someIndex, someList); /// } /// </code> /// </example> public static Boolean IsClamped(this IComparable _this, Object min, Object max) { Throw.If.Object.IsNull(_this, nameof(_this)); Boolean result = true; result &= min == null || _this.IsGreaterThanOrEqual(min); result &= max == null || _this.IsLessThanOrEqual(max); return(result); }