public static void VerifyLessThan <T>(this IComparable <T> item, T value, string parameterName) { if (item.IsGreaterThanOrEqualTo(value)) { throw new ArgumentOutOfRangeException(parameterName); } }
public static void IsGreaterThanOrEqualTo() { IComparable <string> instance = null; string value = null; var result = false; When("an extension is called", () => { Act(() => { result = instance.IsGreaterThanOrEqualTo(value); }); And("an instance is null", () => { instance = null; Should("return false", () => { Assert.That(result, Is.False); }); }); And("an instance is not null", () => { value = "121"; And("the instance is less than the value", () => { instance = "111"; Should("return false", () => { Assert.That(result, Is.False); }); }); And("the instance is greater than the value", () => { instance = "131"; Should("return true", () => { Assert.That(result, Is.True); }); }); And("the instance is equal to the value", () => { instance = "121"; Should("return true", () => { Assert.That(result, Is.True); }); }); }); }); }
public void When_IsGreaterThanOrEqualTo_is_called_with_a_same_value() { // Arrange. IComparable <int> value = 10; // Act. bool result = value.IsGreaterThanOrEqualTo(10); // Assert. result.Should().Be(true); }
public static bool IsBetween <T>(this IComparable <T> item, T minimum, T maximum, bool inclusive) { if (inclusive) { return(item.IsGreaterThanOrEqualTo(minimum) || item.IsLessThanOrEqualTo(maximum)); } else { return(item.IsGreaterThan(minimum) || item.IsLessThan(maximum)); } }
/// <summary> /// Returns whether the specified <see cref="IComparable"/> is between two ranges (inclusive) /// </summary> public static bool IsBetweenInclusive(this IComparable comparable, IComparable lower, IComparable upper) => comparable.IsGreaterThanOrEqualTo(lower) && comparable.IsLessThanOrEqualTo(upper);