public void TestBoundaryNegativeInfinityValue() { double?infOk = double.NegativeInfinity; double?infFail = double.PositiveInfinity; double?empty = null; DoesNotThrow(() => new RangeBoundaryFrom <double?>(infOk, RangeBoundaryFromKind.Infinite)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infOk, RangeBoundaryFromKind.Empty)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infFail, RangeBoundaryFromKind.Empty)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infFail, RangeBoundaryFromKind.Infinite)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infOk, RangeBoundaryFromKind.Inclusive)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infFail, RangeBoundaryFromKind.Inclusive)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infOk, RangeBoundaryFromKind.Exclusive)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(infFail, RangeBoundaryFromKind.Exclusive)); AreEqual( RangeBoundaryFrom <double?> .NegativeInfinity, Range.BoundaryFrom(infOk)); AreEqual( RangeBoundaryFrom <double?> .NegativeInfinity, Range.BoundaryFromExclusive(infOk)); AreEqual( RangeBoundaryFrom <double> .NegativeInfinity, Range.BoundaryFrom(infOk.Value)); AreEqual( RangeBoundaryFrom <double> .NegativeInfinity, Range.BoundaryFromExclusive(infOk.Value)); AreEqual( Range.BoundaryFromExclusive(infOk).GetValueOrDefault(), empty); }
public static void TestBoundaryValueComparison() { int?value1 = 1; int?value2 = 2; var eFrom = RangeBoundaryFrom <int?> .Empty; var nInf = Range.BoundaryFromInfinity <int?>(); var pInf = Range.BoundaryToInfinity <int?>(); var fromInc1 = Range.BoundaryFrom(value1); var fromEx1 = Range.BoundaryFromExclusive(value1); var toInc1 = Range.BoundaryTo(value1); var toEx1 = Range.BoundaryToExclusive(value1); var fromInc2 = Range.BoundaryFrom(value2); var fromEx2 = Range.BoundaryFromExclusive(value2); var toInc2 = Range.BoundaryTo(value2); var toEx2 = Range.BoundaryToExclusive(value2); IsTrue(eFrom < nInf); IsTrue(nInf < toEx1); IsTrue(toEx1 < fromInc1); IsTrue(fromInc1 <= toInc1); IsTrue(toInc1 < fromEx1); IsTrue(fromEx1 < toEx2); IsTrue(toEx2 < fromInc2); IsTrue(fromInc2 <= toInc2); IsTrue(toInc2 < fromEx2); IsTrue(fromEx2 < pInf); }
public static void TestRangeEquality() { int?value1 = 1; int?value2 = 2; int?empty = null; var key = "Hello!"; var key2 = "Hello2!"; var eFrom = new RangeBoundaryFrom <int?>(); var eTo = new RangeBoundaryTo <int?>(); AreEqual(Range <int?> .Empty, Range.Create(eFrom, eTo)); AreEqual(Range <int?> .Infinite, Range.Create(empty, empty)); AreNotEqual(Range <double?> .Infinite, Range.Create(empty, empty)); AreEqual( Range.CreateExclusiveFrom(value1, value2).From, Range.BoundaryFromExclusive(value1)); AreEqual( Range.CreateExclusiveFrom(value1, value2).To, Range.BoundaryTo(value2)); AreNotEqual( Range.CreateExclusiveFrom(value1, value2), Range.Create(value1, value2)); IsTrue(Range.Create(value1, value2) == Range.Create <int?>(1, 2)); IsTrue(Range.Create(value1, value2) != Range.Create(value1, 1)); IsTrue(Range.Create(value1, value2, key) == Range.Create <int?, string>(1, 2, key)); IsTrue(Range.Create(value1, value2, key) != Range.Create <int?, string>(1, 2, key2)); IsTrue(Range.Create(value1, value2, key) != Range.Create <int?, string>(1, 1, key)); }
public void TestBoundaryFromComplementation() { int?value1 = 1; int?value2 = 2; var boundary = Range.BoundaryFrom(value1); var boundaryCompl = boundary.GetComplementation(); IsTrue(boundaryCompl.IsComplementationFor(boundary)); IsFalse(boundaryCompl.IsComplementationFor(Range.BoundaryFrom(value2))); IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryFrom <int?> .Empty)); IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryFrom <int?> .NegativeInfinity)); AreEqual(boundaryCompl.Value, 1); AreEqual(boundaryCompl.Kind, RangeBoundaryToKind.Exclusive); AreEqual(boundaryCompl.GetComplementation(), boundary); boundary = Range.BoundaryFromExclusive(value1); boundaryCompl = boundary.GetComplementation(); IsTrue(boundaryCompl.IsComplementationFor(boundary)); IsFalse(boundaryCompl.IsComplementationFor(Range.BoundaryFrom(value2))); IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryFrom <int?> .Empty)); IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryFrom <int?> .NegativeInfinity)); AreEqual(boundaryCompl.Value, 1); AreEqual(boundaryCompl.Kind, RangeBoundaryToKind.Inclusive); AreEqual(boundaryCompl.GetComplementation(), boundary); boundary = RangeBoundaryFrom <int?> .Empty; Throws <InvalidOperationException>(() => boundary.GetComplementation()); boundary = RangeBoundaryFrom <int?> .NegativeInfinity; Throws <InvalidOperationException>(() => boundary.GetComplementation()); }
/// <summary> /// Replaces inclusive boundaries with exclusive ones with the values from the selector callbacks /// </summary> /// <typeparam name="T">The type of the range values.</typeparam> /// <param name="range">The source range.</param> /// <param name="fromValueSelector">Callback to obtain a new value for the From boundary. Used if the boundary is inclusive.</param> /// <param name="toValueSelector">Callback to obtain a new value for the To boundary. Used if the boundary is inclusive.</param> /// <returns>A range with exclusive boundaries.</returns> public static Range <T> MakeExclusive <T>( this Range <T> range, [NotNull, InstantHandle] Func <T, T> fromValueSelector, [NotNull, InstantHandle] Func <T, T> toValueSelector) { if (range.IsEmpty || (!range.From.IsInclusiveBoundary && !range.To.IsInclusiveBoundary)) { return(range); } var from = range.From; if (from.IsInclusiveBoundary) { from = Range.BoundaryFromExclusive(fromValueSelector(from.GetValueOrDefault())); } var to = range.To; if (to.IsInclusiveBoundary) { to = Range.BoundaryToExclusive(toValueSelector(to.GetValueOrDefault())); } return(range.TryCreateRange(from, to)); }
public static void TestBoundaryRawValueComparison() { int?value1 = 1; int?value2 = 2; int?empty = null; var eFrom = RangeBoundaryFrom <int?> .Empty; var nInf = Range.BoundaryFromInfinity <int?>(); var pInf = Range.BoundaryToInfinity <int?>(); var fromInc1 = Range.BoundaryFrom(value1); var fromEx1 = Range.BoundaryFromExclusive(value1); var toInc1 = Range.BoundaryTo(value1); var toEx1 = Range.BoundaryToExclusive(value1); var fromInc2 = Range.BoundaryFrom(value2); var fromEx2 = Range.BoundaryFromExclusive(value2); var toInc2 = Range.BoundaryTo(value2); var toEx2 = Range.BoundaryToExclusive(value2); IsTrue(eFrom < empty); IsTrue(nInf <= empty); IsTrue(nInf >= empty); IsTrue(pInf > empty); IsTrue(toEx1 > empty); IsTrue(toInc1 > empty); IsTrue(fromEx2 > empty); IsTrue(fromInc2 > empty); IsTrue(empty < toEx2); IsTrue(empty < toInc2); IsTrue(empty < fromEx1); IsTrue(empty < fromInc1); IsTrue(nInf < value1); IsTrue(toEx1 < value1); IsTrue(fromEx1 > value1); IsTrue(toInc1 <= value1); IsTrue(fromInc1 >= value1); IsTrue(toEx1 < value2); IsTrue(fromEx1 < value2); IsTrue(toInc1 < value2); IsTrue(fromInc1 < value2); IsTrue(value2 < pInf); IsTrue(value2 > toEx2); IsTrue(value2 < fromEx2); IsTrue(value2 >= toInc2); IsTrue(value2 <= fromInc2); IsTrue(value1 < toEx2); IsTrue(value1 < fromEx2); IsTrue(value1 < toInc2); IsTrue(value1 < fromInc2); }
public static void TestRangeContains() { double?empty = null; double?value1 = 1; double?value2 = 2; var emptyFrom = RangeBoundaryFrom <double?> .Empty; var emptyTo = RangeBoundaryTo <double?> .Empty; var range = Range.Create(value1, value2); IsFalse(range.Contains(null)); IsFalse(range.Contains(double.NegativeInfinity)); IsFalse(range.Contains(double.PositiveInfinity)); IsFalse(range.Contains(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.Contains(RangeBoundaryTo <double?> .Empty)); IsFalse(range.Contains(0)); IsTrue(range.Contains(1)); IsTrue(range.Contains(1.5)); IsTrue(range.Contains(2)); IsFalse(range.Contains(3)); range = Range.Create(emptyFrom, emptyTo); IsFalse(range.Contains(null)); IsFalse(range.Contains(double.NegativeInfinity)); IsFalse(range.Contains(double.PositiveInfinity)); IsTrue(range.Contains(RangeBoundaryFrom <double?> .Empty)); IsTrue(range.Contains(RangeBoundaryTo <double?> .Empty)); IsFalse(range.Contains(0)); range = Range.CreateExclusive(empty, empty); IsTrue(range.Contains(null)); IsTrue(range.Contains(double.NegativeInfinity)); IsTrue(range.Contains(double.PositiveInfinity)); IsFalse(range.Contains(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.Contains(RangeBoundaryTo <double?> .Empty)); IsTrue(range.Contains(0)); range = Range.CreateExclusive(value1, value2); IsFalse(range.Contains(1)); IsTrue(range.Contains(1.5)); IsFalse(range.Contains(2)); range = Range.CreateExclusive(value1, value2); IsFalse(range.Contains(Range.BoundaryFrom <double?>(1))); IsFalse(range.Contains(Range.BoundaryTo <double?>(2))); IsTrue(range.Contains(Range.BoundaryFromExclusive <double?>(1))); IsTrue(range.Contains(Range.BoundaryFromExclusive <double?>(1.5))); IsFalse(range.Contains(Range.BoundaryFromExclusive <double?>(2))); IsFalse(range.Contains(Range.BoundaryToExclusive <double?>(1))); IsTrue(range.Contains(Range.BoundaryToExclusive <double?>(1.5))); IsTrue(range.Contains(Range.BoundaryToExclusive <double?>(2))); Throws <ArgumentException>( () => range.Contains(Range.BoundaryFrom <double?>(double.PositiveInfinity))); Throws <ArgumentException>( () => range.Contains(Range.BoundaryTo <double?>(double.NegativeInfinity))); }
public void TestBoundaryFromProperties() { int?value1 = 1; int?value2 = 2; int?empty = null; var a = new RangeBoundaryFrom <int?>(); AreEqual(a.Kind, RangeBoundaryFromKind.Empty); AreEqual(a.GetValueOrDefault(), empty); Throws <InvalidOperationException>(() => a.Value.ToString()); IsTrue(a.IsEmpty); IsFalse(a.IsNotEmpty); IsFalse(a.HasValue); IsFalse(a.IsNegativeInfinity); IsFalse(a.IsInclusiveBoundary); IsFalse(a.IsExclusiveBoundary); a = Range.BoundaryFromInfinity <int?>(); AreEqual(a.Kind, RangeBoundaryFromKind.Infinite); AreEqual(a.GetValueOrDefault(), empty); Throws <InvalidOperationException>(() => a.Value.ToString()); IsFalse(a.IsEmpty); IsTrue(a.IsNotEmpty); IsFalse(a.HasValue); IsTrue(a.IsNegativeInfinity); IsFalse(a.IsInclusiveBoundary); IsFalse(a.IsExclusiveBoundary); a = Range.BoundaryFrom(value1); AreEqual(a.Kind, RangeBoundaryFromKind.Inclusive); AreEqual(a.Value, value1); AreNotEqual(a.Value, value2); IsFalse(a.IsEmpty); IsTrue(a.IsNotEmpty); IsTrue(a.HasValue); IsFalse(a.IsNegativeInfinity); IsTrue(a.IsInclusiveBoundary); IsFalse(a.IsExclusiveBoundary); a = Range.BoundaryFromExclusive(value1); AreEqual(a.Kind, RangeBoundaryFromKind.Exclusive); AreEqual(a.Value, value1); AreNotEqual(a.Value, value2); IsFalse(a.IsEmpty); IsTrue(a.IsNotEmpty); IsTrue(a.HasValue); IsFalse(a.IsNegativeInfinity); IsFalse(a.IsInclusiveBoundary); IsTrue(a.IsExclusiveBoundary); }
public static void TestBoundaryKindComparison() { int?value1 = 1; var eFrom = RangeBoundaryFrom <int?> .Empty; var eTo = RangeBoundaryTo <int?> .Empty; var nInf = Range.BoundaryFromInfinity <int?>(); var pInf = Range.BoundaryToInfinity <int?>(); var fromInc = Range.BoundaryFrom(value1); var fromEx = Range.BoundaryFromExclusive(value1); var toInc = Range.BoundaryTo(value1); var toEx = Range.BoundaryToExclusive(value1); AreNotEqual(fromInc, fromEx); AreNotEqual(fromInc, toInc); AreNotEqual(toInc, toEx); AreEqual(fromInc.Value, fromEx.Value); AreEqual(fromInc.Value, toInc.Value); AreEqual(toInc.Value, toEx.Value); // priority: // '∅' < '-∞' < 'a)' < '[a' == 'a]' < '(a' < '+∞' AreEqual(eFrom.CompareTo(eTo), 0); AreEqual(eTo.CompareTo(eFrom), 0); Less(eFrom, nInf); Less(nInf, toEx); Less(toEx, fromInc); AreEqual(fromInc.CompareTo(toInc), 0); AreEqual(toInc.CompareTo(fromInc), 0); Less(toInc, fromEx); Less(fromEx, pInf); IsTrue(eTo <= eFrom); IsTrue(eFrom < nInf); IsTrue(nInf < toEx); IsTrue(toEx < fromInc); IsTrue(toInc <= fromInc && toInc >= fromInc); IsTrue(fromInc < fromEx); IsTrue(fromEx < pInf); IsTrue(pInf >= fromEx); IsTrue(fromEx >= fromInc); IsTrue(fromInc >= toInc); IsTrue(fromInc >= toEx); IsTrue(toEx >= nInf); IsTrue(nInf >= eFrom); IsTrue(eFrom >= eTo); }
public static void TestBoundaryToString() { int?value1 = 1; AreEqual(RangeBoundaryFrom <int?> .Empty.ToString(), "∅"); AreEqual(RangeBoundaryTo <int?> .Empty.ToString(), "∅"); AreEqual(RangeBoundaryFrom <int?> .NegativeInfinity.ToString(), "(-∞"); AreEqual(RangeBoundaryTo <int?> .PositiveInfinity.ToString(), "+∞)"); AreEqual(Range.BoundaryFrom(value1).ToString(), "[1"); AreEqual(Range.BoundaryFromExclusive(value1).ToString(), "(1"); AreEqual(Range.BoundaryTo(value1).ToString(), "1]"); AreEqual(Range.BoundaryToExclusive(value1).ToString(), "1)"); AreEqual(Range.BoundaryToExclusive(value1).ToString("000"), "001)"); AreEqual(RangeBoundaryTo <int?> .Empty.ToString("000"), "∅"); AreEqual(RangeBoundaryFrom <int?> .NegativeInfinity.ToString("000"), "(-∞"); }
public static void TestRangeExtendFrom() { double?empty = null; double?value1 = 1; double?value2 = 2; var emptyFrom = RangeBoundaryFrom <double?> .Empty; var emptyTo = RangeBoundaryTo <double?> .Empty; var range = Range.Create(value1, value2); AreEqual(range.ExtendFrom(null), Range.Create(empty, value2)); AreEqual(range.ExtendFrom(double.NegativeInfinity), Range.Create(empty, value2)); Throws <ArgumentException>(() => range.ExtendFrom(double.PositiveInfinity)); AreEqual(range.ExtendFrom(RangeBoundaryFrom <double?> .Empty), range); AreEqual(range.ExtendFrom(0), Range.Create(0, value2)); AreEqual(range.ExtendFrom(1), range); AreEqual(range.ExtendFrom(1.5), range); AreEqual(range.ExtendFrom(2), range); AreEqual(range.ExtendFrom(3), range); range = Range.Create(emptyFrom, emptyTo); AreEqual(range.ExtendFrom(null), range); AreEqual(range.ExtendFrom(double.NegativeInfinity), range); Throws <ArgumentException>(() => range.ExtendFrom(double.PositiveInfinity)); AreEqual(range.ExtendFrom(RangeBoundaryFrom <double?> .Empty), range); AreEqual(range.ExtendFrom(0), range); range = Range.CreateExclusive(empty, empty); AreEqual(range.ExtendFrom(null), range); AreEqual(range.ExtendFrom(double.NegativeInfinity), range); Throws <ArgumentException>(() => range.ExtendFrom(double.PositiveInfinity)); AreEqual(range.ExtendFrom(RangeBoundaryFrom <double?> .Empty), range); AreEqual(range.ExtendFrom(0), range); range = Range.CreateExclusive(value1, value2); AreEqual(range.ExtendFrom(1), Range.CreateExclusiveTo(1, value2)); AreEqual(range.ExtendFrom(1.5), range); AreEqual(range.ExtendFrom(2), range); range = Range.CreateExclusive(value1, value2); AreEqual(range.ExtendFrom(Range.BoundaryFrom <double?>(1)), Range.CreateExclusiveTo(1, value2)); AreEqual(range.ExtendFrom(Range.BoundaryFromExclusive <double?>(1)), range); AreEqual(range.ExtendFrom(Range.BoundaryFromExclusive <double?>(0)), Range.CreateExclusive(0, value2)); }
public void TestBoundaryFromCreation() { int?value1 = 1; int?value2 = 2; int?empty = null; DoesNotThrow(() => new RangeBoundaryFrom <int?>(empty, RangeBoundaryFromKind.Empty)); DoesNotThrow(() => new RangeBoundaryFrom <int?>(empty, RangeBoundaryFromKind.Infinite)); DoesNotThrow(() => new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Exclusive)); DoesNotThrow(() => new RangeBoundaryFrom <int?>(value2, RangeBoundaryFromKind.Inclusive)); DoesNotThrow(() => new RangeBoundaryFrom <double?>(double.NaN, RangeBoundaryFromKind.Empty)); Throws <ArgumentException>(() => new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Empty)); Throws <ArgumentException>(() => new RangeBoundaryFrom <int?>(value2, RangeBoundaryFromKind.Infinite)); Throws <ArgumentException>(() => new RangeBoundaryFrom <int?>(empty, RangeBoundaryFromKind.Inclusive)); Throws <ArgumentException>(() => new RangeBoundaryFrom <int?>(empty, RangeBoundaryFromKind.Exclusive)); Throws <ArgumentException>(() => new RangeBoundaryFrom <double?>(double.NaN, RangeBoundaryFromKind.Exclusive)); AreEqual( RangeBoundaryFrom <int?> .NegativeInfinity, Range.BoundaryFromInfinity <int?>()); AreEqual( RangeBoundaryFrom <int?> .NegativeInfinity, Range.BoundaryFrom(empty)); AreEqual( RangeBoundaryFrom <int?> .NegativeInfinity, Range.BoundaryFromExclusive(empty)); AreEqual( new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Inclusive), Range.BoundaryFrom(value1)); AreEqual( new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Exclusive), Range.BoundaryFromExclusive(value1)); AreNotEqual( new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Exclusive), Range.BoundaryFromExclusive(value2)); AreNotEqual( RangeBoundaryFrom <int> .NegativeInfinity, Range.BoundaryFrom(0)); AreEqual( new RangeBoundaryFrom <int?>(value1, RangeBoundaryFromKind.Exclusive), Range.BoundaryFromExclusive(value1)); }
public void TestBoundaryFromWithValue() { int?value1 = 1; int?value2 = 2; var boundary = Range.BoundaryFrom(value1); var boundary2 = boundary.WithValue(i => i + 1); AreEqual(boundary.Kind, boundary2.Kind); AreEqual(boundary2.Value, value2); boundary = Range.BoundaryFromExclusive(value1); boundary2 = boundary.WithValue(i => i + 1); AreEqual(boundary.Kind, boundary2.Kind); AreEqual(boundary2.Value, value2); boundary = RangeBoundaryFrom <int?> .Empty; boundary2 = boundary.WithValue(i => i + 1); AreEqual(boundary, boundary2); boundary = RangeBoundaryFrom <int?> .NegativeInfinity; boundary2 = boundary.WithValue(i => i + 1); AreEqual(boundary, boundary2); }
public Range <T, TKey> MakeExclusive( [NotNull, InstantHandle] Func <T, T> fromValueSelector, [NotNull, InstantHandle] Func <T, T> toValueSelector) { if (IsEmpty || (!From.IsInclusiveBoundary && !To.IsInclusiveBoundary)) { return(this); } var from = From; if (from.IsInclusiveBoundary) { from = Range.BoundaryFromExclusive(fromValueSelector(from.GetValueOrDefault())); } var to = To; if (to.IsInclusiveBoundary) { to = Range.BoundaryToExclusive(toValueSelector(to.GetValueOrDefault())); } return(TryCreateRange(from, to)); }
public void TestBoundaryFromToInclusive() { int?value1 = 1; int?empty = null; var boundary = RangeBoundaryFrom <int?> .Empty; var boundary2 = boundary.ToInclusive(); IsTrue(boundary2.IsEmpty); boundary = Range.BoundaryFrom(empty); boundary2 = boundary.ToInclusive(); IsTrue(boundary2.IsNegativeInfinity); boundary = Range.BoundaryFrom(value1); boundary2 = boundary.ToInclusive(); AreEqual(boundary2.Value, boundary.Value); AreEqual(boundary2.Kind, RangeBoundaryFromKind.Inclusive); boundary = Range.BoundaryFromExclusive(value1); boundary2 = boundary.ToInclusive(); AreEqual(boundary2.Value, boundary.Value); AreEqual(boundary2.Kind, RangeBoundaryFromKind.Inclusive); }
public static void TestKeyedRangeStartsAfter() { double?empty = null; double?value1 = 1; double?value2 = 2; var emptyFrom = RangeBoundaryFrom <double?> .Empty; var emptyTo = RangeBoundaryTo <double?> .Empty; var range = Range.Create(value1, value2, _rangeKey); IsTrue(range.StartsAfter(null)); IsTrue(range.StartsAfter(double.NegativeInfinity)); IsFalse(range.StartsAfter(double.PositiveInfinity)); IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty)); IsTrue(range.StartsAfter(0)); IsFalse(range.StartsAfter(1)); IsFalse(range.StartsAfter(1.5)); IsFalse(range.StartsAfter(2)); IsFalse(range.StartsAfter(3)); IsTrue(range.StartsAfter(Range.Create(empty, 0, _rangeKey2))); IsTrue(range.StartsAfter(Range.CreateExclusiveTo(empty, 1, _rangeKey2))); IsFalse(range.StartsAfter(Range.Create(empty, 1, _rangeKey2))); range = Range.Create(emptyFrom, emptyTo, _rangeKey); IsFalse(range.StartsAfter(null)); IsFalse(range.StartsAfter(double.NegativeInfinity)); IsFalse(range.StartsAfter(double.PositiveInfinity)); IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty)); IsFalse(range.StartsAfter(0)); range = Range.CreateExclusive(empty, empty, _rangeKey); IsFalse(range.StartsAfter(null)); IsFalse(range.StartsAfter(double.NegativeInfinity)); IsFalse(range.StartsAfter(double.PositiveInfinity)); IsFalse(range.StartsAfter(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.StartsAfter(RangeBoundaryTo <double?> .Empty)); IsFalse(range.StartsAfter(0)); range = Range.CreateExclusive(value1, value2, _rangeKey); IsTrue(range.StartsAfter(1)); IsFalse(range.StartsAfter(1.5)); IsFalse(range.StartsAfter(2)); range = Range.CreateExclusive(value1, value2, _rangeKey); IsTrue(range.StartsAfter(Range.BoundaryFrom <double?>(1))); IsFalse(range.StartsAfter(Range.BoundaryTo <double?>(2))); IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(1))); IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(1.5))); IsFalse(range.StartsAfter(Range.BoundaryFromExclusive <double?>(2))); IsTrue(range.StartsAfter(Range.BoundaryToExclusive <double?>(1))); IsFalse(range.StartsAfter(Range.BoundaryToExclusive <double?>(1.5))); IsFalse(range.StartsAfter(Range.BoundaryToExclusive <double?>(2))); Throws <ArgumentException>( () => range.StartsAfter(Range.BoundaryFrom <double?>(double.PositiveInfinity))); Throws <ArgumentException>( () => range.StartsAfter(Range.BoundaryTo <double?>(double.NegativeInfinity))); }
public static void TestKeyedRangeEndsBefore() { double?empty = null; double?value1 = 1; double?value2 = 2; var emptyFrom = RangeBoundaryFrom <double?> .Empty; var emptyTo = RangeBoundaryTo <double?> .Empty; var range = Range.Create(value1, value2, RangeKey); IsTrue(range.EndsBefore(null)); IsFalse(range.EndsBefore(double.NegativeInfinity)); IsTrue(range.EndsBefore(double.PositiveInfinity)); IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty)); IsFalse(range.EndsBefore(0)); IsFalse(range.EndsBefore(1)); IsFalse(range.EndsBefore(1.5)); IsFalse(range.EndsBefore(2)); IsTrue(range.EndsBefore(3)); IsFalse(range.EndsBefore(Range.Create(2, empty, RangeKey2))); IsTrue(range.EndsBefore(Range.CreateExclusiveFrom(2, empty, RangeKey2))); IsTrue(range.EndsBefore(Range.Create(3, empty, RangeKey2))); range = Range.Create(emptyFrom, emptyTo, RangeKey); IsFalse(range.EndsBefore(null)); IsFalse(range.EndsBefore(double.NegativeInfinity)); IsFalse(range.EndsBefore(double.PositiveInfinity)); IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty)); IsFalse(range.EndsBefore(0)); range = Range.CreateExclusive(empty, empty, RangeKey); IsFalse(range.EndsBefore(null)); IsFalse(range.EndsBefore(double.NegativeInfinity)); IsFalse(range.EndsBefore(double.PositiveInfinity)); IsFalse(range.EndsBefore(RangeBoundaryFrom <double?> .Empty)); IsFalse(range.EndsBefore(RangeBoundaryTo <double?> .Empty)); IsFalse(range.EndsBefore(0)); range = Range.CreateExclusive(value1, value2, RangeKey); IsFalse(range.EndsBefore(1)); IsFalse(range.EndsBefore(1.5)); IsTrue(range.EndsBefore(2)); range = Range.CreateExclusive(value1, value2, RangeKey); IsFalse(range.EndsBefore(Range.BoundaryFrom <double?>(1))); IsTrue(range.EndsBefore(Range.BoundaryTo <double?>(2))); IsFalse(range.EndsBefore(Range.BoundaryFromExclusive <double?>(1))); IsFalse(range.EndsBefore(Range.BoundaryFromExclusive <double?>(1.5))); IsTrue(range.EndsBefore(Range.BoundaryFromExclusive <double?>(2))); IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(1))); IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(1.5))); IsFalse(range.EndsBefore(Range.BoundaryToExclusive <double?>(2))); Throws <ArgumentException>( () => range.EndsBefore(Range.BoundaryFrom <double?>(double.PositiveInfinity))); Throws <ArgumentException>( () => range.EndsBefore(Range.BoundaryTo <double?>(double.NegativeInfinity))); }