/// <summary> /// Checks whether the value is smaller as the reference value. /// </summary> /// <param name="value">The value to test.</param> /// <param name="referenceValue">The reference value to test.</param> /// <param name="paramName">The name of the parameter that caused the exception.</param> /// <param name="message">A message that describes the error.</param> /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of /// range.</exception> public static void IsSmaller(IComparable value, IComparable referenceValue, string paramName, string message) { if (!value.IsSmaller(referenceValue)) { throw new ArgumentOutOfRangeException(paramName, referenceValue, message); } }
/// <summary> /// Checks whether the value is smaller as the reference value. /// </summary> /// <param name="value">The value to test.</param> /// <param name="referenceValue">The reference value to test.</param> /// <exception cref="ArgumentOutOfRangeException"><em>value</em> is out of /// range.</exception> public static void IsSmaller(IComparable value, IComparable referenceValue) { if (!value.IsSmaller(referenceValue)) { throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Indicates whether the instance is smaller or equal to the reference value. /// </summary> /// <param name="value">The instance to test.</param> /// <param name="referenceValue">The reference value to test.</param> /// <returns><strong>true</strong> if the instance is smaller or equal to the reference /// value; otherwise, <strong>false</strong>.</returns> /// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is /// <strong>null</strong>.</exception> public static bool IsSmallerOrEqual(this IComparable value, IComparable referenceValue) { Precondition.IsNotNull(value, nameof(value)); Precondition.IsNotNull(referenceValue, nameof(referenceValue)); return(value.IsSmaller(referenceValue) || value.IsEqual(referenceValue)); }
public void IsSmaller_VariousUseCases_ReturnExpectedResult( IComparable first, IComparable second, bool expectedResult) { // Call bool isFirstBiggerThenSecond = first.IsSmaller(second); // Assert Assert.AreEqual(expectedResult, isFirstBiggerThenSecond); }
public static IComparable GetFirstValueBiggerThan(IComparable value, IList values) { int i = values.Count - 1; while (i > -1 && (value.IsSmaller((IComparable)values[i]))) { i--; } var itemIndex = i + 1; if (itemIndex == values.Count ) return null; return (IComparable)values[itemIndex]; }
/// <summary> /// Determines where one object is within the inclusive bounds of some range. /// </summary> /// <param name="value">Value to be checked.</param> /// <param name="limit1">First range value.</param> /// <param name="limit2">Second range value.</param> /// <returns><c>true</c> if <paramref name="value"/> falls within the inclusive bounds, /// <c>false</c> otherwise.</returns> /// <exception cref="ArgumentException">Thrown when object type of <paramref name="value"/> /// is not the same as that of <paramref name="limit1"/> or <paramref name="limit2"/>.</exception> public static bool IsInRange(this IComparable value, IComparable limit1, IComparable limit2) { IComparable min; IComparable max; if (limit1.IsSmaller(limit2)) { min = limit1; max = limit2; } else { min = limit2; max = limit1; } return(min.IsSmaller(value) && max.IsBigger(value) || min.CompareTo(value) == 0 || max.CompareTo(value) == 0); }
public static bool IsInRange(this IComparable value, IComparable limitOne, IComparable limitTwo) { IComparable min; IComparable max; if (limitOne.IsSmaller(limitTwo)) { min = limitOne; max = limitTwo; } else { min = limitTwo; max = limitOne; } return((min.IsSmaller(value) && max.IsBigger(value)) || min.CompareTo(value) == 0 || max.CompareTo(value) == 0); }
public static bool IsInRange(this IComparable value, IComparable limitOne, IComparable limitTwo) { IComparable min; IComparable max; if (limitOne.IsSmaller(limitTwo)) { min = limitOne; max = limitTwo; } else { min = limitTwo; max = limitOne; } return (min.IsSmaller(value) && max.IsBigger(value)) || min.CompareTo(value) == 0 || max.CompareTo(value) == 0; }
public void IsSmaller_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter) { AssertThrowsException<ArgumentNullException>(() => value.IsSmaller(referenceValue), expectedParameter); }
public void IsSmaller_Throws_ArgumentNullException(IComparable value, IComparable referenceValue, string expectedParameter) { AssertThrowsException <ArgumentNullException>(() => value.IsSmaller(referenceValue), expectedParameter); }