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 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 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 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)); }