Esempio n. 1
0
        /// <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 TestBoundaryToComplementation()
        {
            int?value1 = 1;
            int?value2 = 2;

            var boundary      = Range.BoundaryTo(value1);
            var boundaryCompl = boundary.GetComplementation();

            IsTrue(boundaryCompl.IsComplementationFor(boundary));
            IsFalse(boundaryCompl.IsComplementationFor(Range.BoundaryTo(value2)));
            IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryTo <int?> .Empty));
            IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryTo <int?> .PositiveInfinity));
            AreEqual(boundaryCompl.Value, 1);
            AreEqual(boundaryCompl.Kind, RangeBoundaryFromKind.Exclusive);
            AreEqual(boundaryCompl.GetComplementation(), boundary);

            boundary      = Range.BoundaryToExclusive(value1);
            boundaryCompl = boundary.GetComplementation();
            IsTrue(boundaryCompl.IsComplementationFor(boundary));
            IsFalse(boundaryCompl.IsComplementationFor(Range.BoundaryTo(value2)));
            IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryTo <int?> .Empty));
            IsFalse(boundaryCompl.IsComplementationFor(RangeBoundaryTo <int?> .PositiveInfinity));
            AreEqual(boundaryCompl.Value, 1);
            AreEqual(boundaryCompl.Kind, RangeBoundaryFromKind.Inclusive);
            AreEqual(boundaryCompl.GetComplementation(), boundary);

            boundary = RangeBoundaryTo <int?> .Empty;
            Throws <InvalidOperationException>(() => boundary.GetComplementation());
            boundary = RangeBoundaryTo <int?> .PositiveInfinity;
            Throws <InvalidOperationException>(() => boundary.GetComplementation());
        }
        public static void TestBoundaryPositiveInfinityValue()
        {
            double?infOk   = double.PositiveInfinity;
            double?infFail = double.NegativeInfinity;
            double?empty   = null;

            DoesNotThrow(() => new RangeBoundaryTo <double?>(infOk, RangeBoundaryToKind.Infinite));

            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infOk, RangeBoundaryToKind.Empty));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infFail, RangeBoundaryToKind.Empty));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infFail, RangeBoundaryToKind.Infinite));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infOk, RangeBoundaryToKind.Inclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infFail, RangeBoundaryToKind.Inclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infOk, RangeBoundaryToKind.Exclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(infFail, RangeBoundaryToKind.Exclusive));

            AreEqual(
                RangeBoundaryTo <double?> .PositiveInfinity,
                Range.BoundaryTo(infOk));
            AreEqual(
                RangeBoundaryTo <double?> .PositiveInfinity,
                Range.BoundaryToExclusive(infOk));

            AreEqual(
                RangeBoundaryTo <double> .PositiveInfinity,
                Range.BoundaryTo(infOk.Value));
            AreEqual(
                RangeBoundaryTo <double> .PositiveInfinity,
                Range.BoundaryToExclusive(infOk.Value));

            AreEqual(
                Range.BoundaryToExclusive(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);
        }
Esempio n. 5
0
        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 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 TestBoundaryToProperties()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;

            var a = new RangeBoundaryTo <int?>();

            AreEqual(a.Kind, RangeBoundaryToKind.Empty);
            AreEqual(a.GetValueOrDefault(), empty);
            Throws <InvalidOperationException>(() => a.Value.ToString());

            IsTrue(a.IsEmpty);
            IsFalse(a.IsNotEmpty);
            IsFalse(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            IsFalse(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryToInfinity <int?>();
            AreEqual(a.Kind, RangeBoundaryToKind.Infinite);
            AreEqual(a.GetValueOrDefault(), empty);
            Throws <InvalidOperationException>(() => a.Value.ToString());

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsFalse(a.HasValue);
            IsTrue(a.IsPositiveInfinity);
            IsFalse(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryTo(value1);
            AreEqual(a.Kind, RangeBoundaryToKind.Inclusive);
            AreEqual(a.Value, value1);
            AreNotEqual(a.Value, value2);

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsTrue(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            IsTrue(a.IsInclusiveBoundary);
            IsFalse(a.IsExclusiveBoundary);

            a = Range.BoundaryToExclusive(value1);
            AreEqual(a.Kind, RangeBoundaryToKind.Exclusive);
            AreEqual(a.Value, value1);
            AreNotEqual(a.Value, value2);

            IsFalse(a.IsEmpty);
            IsTrue(a.IsNotEmpty);
            IsTrue(a.HasValue);
            IsFalse(a.IsPositiveInfinity);
            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"), "(-∞");
        }
Esempio n. 10
0
        public static void TestRangeExtendTo()
        {
            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.ExtendTo(null), Range.Create(value1, empty));
            AreEqual(range.ExtendTo(double.PositiveInfinity), Range.Create(value1, empty));
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);
            AreEqual(range.ExtendTo(1), range);
            AreEqual(range.ExtendTo(1.5), range);
            AreEqual(range.ExtendTo(2), range);
            AreEqual(range.ExtendTo(3), Range.Create(value1, 3));

            range = Range.Create(emptyFrom, emptyTo);
            AreEqual(range.ExtendTo(null), range);
            AreEqual(range.ExtendTo(double.PositiveInfinity), range);
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);

            range = Range.CreateExclusive(empty, empty);
            AreEqual(range.ExtendTo(null), range);
            AreEqual(range.ExtendTo(double.PositiveInfinity), range);
            Throws <ArgumentException>(() => range.ExtendTo(double.NegativeInfinity));
            AreEqual(range.ExtendTo(RangeBoundaryTo <double?> .Empty), range);
            AreEqual(range.ExtendTo(0), range);

            range = Range.CreateExclusive(value1, value2);
            AreEqual(range.ExtendTo(1), range);
            AreEqual(range.ExtendTo(1.5), range);
            AreEqual(range.ExtendTo(2), Range.CreateExclusiveFrom(value1, 2));

            range = Range.CreateExclusive(value1, value2);
            AreEqual(range.ExtendTo(Range.BoundaryTo <double?>(2)), Range.CreateExclusiveFrom(value1, 2));
            AreEqual(range.ExtendTo(Range.BoundaryToExclusive <double?>(2)), range);
            AreEqual(range.ExtendTo(Range.BoundaryToExclusive <double?>(3)), Range.CreateExclusive(value1, 3));
        }
Esempio n. 11
0
        public static void TestBoundaryToCreation()
        {
            int?value1 = 1;
            int?value2 = 2;
            int?empty  = null;

            DoesNotThrow(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Empty));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Infinite));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive));
            DoesNotThrow(() => new RangeBoundaryTo <int?>(value2, RangeBoundaryToKind.Inclusive));
            DoesNotThrow(() => new RangeBoundaryTo <double?>(double.NaN, RangeBoundaryToKind.Empty));

            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Empty));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(value2, RangeBoundaryToKind.Infinite));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Inclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <int?>(empty, RangeBoundaryToKind.Exclusive));
            Throws <ArgumentException>(() => new RangeBoundaryTo <double?>(double.NaN, RangeBoundaryToKind.Exclusive));

            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryToInfinity <int?>());
            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryTo(empty));
            AreEqual(
                RangeBoundaryTo <int?> .PositiveInfinity,
                Range.BoundaryToExclusive(empty));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Inclusive),
                Range.BoundaryTo(value1));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value1));
            AreNotEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value2));
            AreNotEqual(
                RangeBoundaryTo <int> .PositiveInfinity,
                Range.BoundaryTo(0));
            AreEqual(
                new RangeBoundaryTo <int?>(value1, RangeBoundaryToKind.Exclusive),
                Range.BoundaryToExclusive(value1));
        }
        public static void TestBoundaryToWithValue()
        {
            int?value1 = 1;
            int?value2 = 2;

            var boundary  = Range.BoundaryTo(value1);
            var boundary2 = boundary.WithValue(i => i + 1);

            AreEqual(boundary.Kind, boundary2.Kind);
            AreEqual(boundary2.Value, value2);

            boundary  = Range.BoundaryToExclusive(value1);
            boundary2 = boundary.WithValue(i => i + 1);
            AreEqual(boundary.Kind, boundary2.Kind);
            AreEqual(boundary2.Value, value2);

            boundary  = RangeBoundaryTo <int?> .Empty;
            boundary2 = boundary.WithValue(i => i + 1);
            AreEqual(boundary, boundary2);
            boundary  = RangeBoundaryTo <int?> .PositiveInfinity;
            boundary2 = boundary.WithValue(i => i + 1);
            AreEqual(boundary, boundary2);
        }
        public static void TestBoundaryToToInclusive()
        {
            int?value1 = 1;
            int?empty  = null;

            var boundary  = RangeBoundaryTo <int?> .Empty;
            var boundary2 = boundary.ToInclusive();

            IsTrue(boundary2.IsEmpty);

            boundary  = Range.BoundaryTo(empty);
            boundary2 = boundary.ToInclusive();
            IsTrue(boundary2.IsPositiveInfinity);

            boundary  = Range.BoundaryTo(value1);
            boundary2 = boundary.ToInclusive();
            AreEqual(boundary2.Value, boundary.Value);
            AreEqual(boundary2.Kind, RangeBoundaryToKind.Inclusive);

            boundary  = Range.BoundaryToExclusive(value1);
            boundary2 = boundary.ToInclusive();
            AreEqual(boundary2.Value, boundary.Value);
            AreEqual(boundary2.Kind, RangeBoundaryToKind.Inclusive);
        }
        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));
        }
Esempio n. 15
0
        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)));
        }
        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)));
        }